Skip to content

Commit

Permalink
Added a small random delay in front of download
Browse files Browse the repository at this point in the history
Fixes EUCA-9760
  • Loading branch information
dmitrii committed Jul 24, 2014
1 parent 0fd778c commit 8f3c75b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions storage/http.c
Expand Up @@ -89,6 +89,7 @@

#include <eucalyptus.h>
#include <log.h>
#include "misc.h"

#ifndef _UNIT_TEST
// http_ functions aren't part of the unit test
Expand All @@ -108,6 +109,7 @@
#define MAX_TIMEOUT 300 //!< in seconds, the cap for growing timeout values
#define STRSIZE 245 //!< for short strings: files, hosts, URLs
#endif /* ! _UNIT_TEST */
#define RANDOM_DELAY_PERCENT 0.01 //!< 1% of current timeout determines max delay duration

/*----------------------------------------------------------------------------*\
| |
Expand Down Expand Up @@ -671,6 +673,16 @@ int http_get_timeout(const char *url, const char *outfile, int total_retries, in
params.total_wrote = 0L;
params.total_calls = 0L;

// Introduce a small random delay before each download to
// spread out parallel download attemps from multiple NCs.
{
unsigned long long max_delay_nanosec = (unsigned long long)
(((float)timeout * NANOSECONDS_IN_SECOND) * RANDOM_DELAY_PERCENT);
unsigned long long random_delay_nanosec = (unsigned long long)
((double)max_delay_nanosec * (rand() / (RAND_MAX + 1.0)));
euca_nanosleep(random_delay_nanosec);
}

result = curl_easy_perform(curl); /* do it */
LOGDEBUG("wrote %lld bytes in %lld writes\n", params.total_wrote, params.total_calls);

Expand Down

0 comments on commit 8f3c75b

Please sign in to comment.