in reply to Efficiently send GET requests under a second

Don't guess how long you can sleep. If you are using Time::HiRes already, check what time it is, compare to the last time, and use that information to sleep the amount you want.
  • Comment on Re (tilly) 1: Efficiently send GET requests under a second

Replies are listed 'Best First'.
RE: Re (tilly) 1: Efficiently send GET requests under a second
by Fastolfe (Vicar) on Oct 03, 2000 at 18:33 UTC
    Agreed. A good algorithm might be to divide up time into discrete seconds (Time::HiRes can override time to provide you with hi-resolution timekeeping), like $time_left = $start_time + 1 - time(), calculate how many more requests you have to do in the remaining fraction of a second, and divide the time into slices, sleeping an appropriate amount of time so that the next slice occurs on time. That would allow your script to adapt to requests that vary in duration (due to network conditions or loading, etc.).