Re: Loading an I/O intensive program into memory



"C++ Newbie" <newbie.cpp@xxxxxxxxxxxxxx> writes:

OK, that's handy to know. It would still be interesting to compare the
relative performance of letting Linux do the RAM buffering and
explicitly loading the lot into RAM.

You can lock programs into memory, but that may or may not help. It
would eliminate the time when the program is swapped out to disk
because another process has higher priority. If that's happening, you
have other problems.

Usually more RAM will allow better disk buffering. The system will
tend to keep as much "disk" in memory as possible.

What's the profile of the CPU when the program is running? Is it CPU
bound, or I/O bound?


Do you mean DIY writing of equivalent programs to grep, sed & awk or
just #including them? I've always thought of #including to be a bit of
a cop-out as you're really just using black boxes :-).

That's really the wrong way to do things. What you want is to have
the flexibility to re-write your program to be as efficient as
possible, which is easier because of sh/sed/grep/awk/sort.

It's easier to redo the main loop of code in shell than in C.
Optimizing in C too early is bad.

The general rule is that 90% of the time is spent in 10% of the code.
That's what you want to optimize. Don't guess. Know before you re-write.

I would try to use shell/awk/sort/etc before C to get the logic optimized.
But you are using C, so .....

Have you done any profiling of your C code?
Where is your program spending 90% of its time?

It's been a while, but you do something like

1) recompile all of your programs using the "-pg" option for
profiling. (and maybe -fprofile-arcs according to the gprof(1) man
page).

2) Run your program with real input to gather the profile data.

3) run the "gprof" program, which calculates the amount of time spend
in each routine. If you only have a few, you many need to add more
just to profile the code.


The real thing to do is to consider the loops of execution. Can the
number of loops be eliminated? Can you remove code from inside the
loop to outside the loop. Are you sorting data, and can you make it
more efficient?

And, or couse, have you compiled the program with optimization enabled?

But it really sounds as if you are doing it backwards. For instance,
if you are using sed, grep and awk, can one of these programs be
eliminated? How many times are they executed in your program?



.



Relevant Pages

  • Re: free RAM problem
    ... I clean every variable after each loop and use the ... Nevertheless my free RAM is falling with run-time length like if each ... How can I force the RAM to clean completely from no-used stuff? ... Also in general if you have enough memory, ...
    (comp.lang.ruby)
  • Perl Memory and die...what is happening here?
    ... This program uses up all the memory deliberatly...but I have some questions ... The first loop will run out of RAM and exit status 1. ...   # Out of Memory when RAM limit is reached, ...
    (comp.lang.perl.misc)
  • Re: How to stop NSString memory leak?
    ... There are so many that if I don't free the memory while in my loop I ... soon run out of ram. ... claiming that there's no doubt that you're done with the *data* that ...
    (comp.sys.mac.programmer.help)
  • Re: Can I abandon the lock on .SyncRoot and lock a collection directly? Less available memory in 2.0
    ... On 6 Apr., 14:47, "Frank Hileman" ... my app is using p to 1300 MB of memory and running fine. ... throwing "out of memory" exceptions (2GB RAM Windows 2003 machines). ... profile which objects use what amount of RAM? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [OT] Switch question
    ... >any steps to optimise this loop. ... program and determined that the switch statement in this loop is using ... Profile after each change. ...
    (comp.lang.c)