Perl: measuring response time of an http api

warrior32 used Ask the Experts™
In perl running multiple threads at the same time, each one calling the same HTTP API how do I measure how long the response time of the API took?

My thoughts were something like this
my $start_time = [gettimeofday];
my $response = $ua->get($url);
my $end_time = [gettimeofday];
my $elapsed_time = tv_interval($start_time,$end_time);
$elapsed_time = $elapsed_time * 1000;

but i am unsure if under multiple threads calling the same API if the time variables will be overwritten. I want to simulate load on the API.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®


I'm using the Parallel::ForkManager to fork the threads.  Does forking new threads do they share variables?
IT Supervisor
Top Expert 2009
I haven't used ForkManager, but if it is indeed fork()ing processes, then there's no worry.

Even if it is using threads instead of fork()s, you should still be safe, since variables need to be specifically shared (via Threads::Shared) in order for the separate threads to be able to access the same values in the same variables.

In other words, in either case, you should fine.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial