in reply to Re^2: Optimizing a large project.
in thread Optimizing a large project.

To know where the problem lies, if in IO or in CPU usage, all you need to do is to run top or any other similar monitoring tool while your program is running. Roughly, if it shows that CPU usage goes over 90%, then your problem is CPU, below 30% it is IO and in the middle it is both.

Well, this method will not work if your application just receives a few events per minute that are processed in less than a second, below the top (and your eyes!) resolution.

Replies are listed 'Best First'.
Re^4: Optimizing a large project.
by salva (Canon) on Jun 13, 2008 at 08:48 UTC
    In the later case, to calculate the CPU usage ratio, you can use something like that:
    my ($cpu_time, $clock_time) = (0, 0); sub your_event_processing { my ($start_user, $start_system) = times; my $start_clock = time; # do the event processing here # ... my ($end_user,$end_system) = times; my $end_clock = time; $clock_time += ($end_clock - $start_clock); $cpu_time += ($end_user - $start_user + end_system - $start_system); } END { printf STDERR "clock_time: %d, cpu_time: %d (%4.2f%%)\n", $clock_time, $cpu_time, $cpu_time * 100 / $clock_time; }
    And let it run for some hundreds of events, so that the rounding errors go away.