git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/6] maintenance: add get_random_minute()

From
Derrick Stolee <derrickstolee@github.com>
Date
Aug 8, 2023, 17:28 UTC
Message-ID
<8854e369-fabb-4044-a06c-eaf5b9fbde4a@github.com>
In-Reply-To
<ZNFgIyuhlNd8I9Y2@nand.local>
On 8/7/2023 5:20 PM, Taylor Blau wrote:
> On Mon, Aug 07, 2023 at 06:51:35PM +0000, Derrick Stolee via GitGitGadget wrote:
Show 12 quoted lines
>> +	if (!random_initialized) {
>> +		srand((unsigned int)getpid());
>> +		random_initialized = 1;
>> +	}
> 
> I was wondering where else we call srand() within Git, and it looks like
> the only other spot is in `lock_file_timeout()`.
> 
> I doubt it, but is there a chance that that code depends on only calling
> srand() once? I think the answer is "no", since we only use rand()
> within that function to generate a random-ish backoff period, so I think
> the repeatability of it doesn't matter all that much.

The main point would be to avoid the cost of spinning up the number generator, but there is potential for a bug if we run both initializers: the lockfile would re-use the same filenames after the generator is reset.

> So I think this is kind of outside the scope of your series, but I
> wonder if we should have a git_rand() that automatically initializes the
> PRNG with the value of getpid()? Then multiple callers can grab random
> values at will without reinitializing the PRNG.

I see you're moving ahead with removing the srand() from the lockfile code, so I'll focus on creating a `git_rand()` that centralizes the use of srand(), but won't touch the code in the lockfile so your patch applies independently.

Thanks, -Stolee

Previous: Taylor BlauNext: Taylor Blau
Message 12 of 47 in “maintenance: schedule maintenance on a random minute”
  1. 0/6 maintenance: schedule maintenance on a random minuteDerrick Stolee via GitGitGadget, Aug 7, 2023
  2. 2/6 maintenance: use random minute in launchctl schedulerDerrick Stolee via GitGitGadget, Aug 7, 2023
  3. Taylor BlauAug 7, 2023
  4. 1/6 maintenance: add get_random_minute()Derrick Stolee via GitGitGadget, Aug 7, 2023
  5. Taylor BlauAug 7, 2023
  6. Junio C HamanoAug 7, 2023
  7. Junio C HamanoAug 8, 2023
  8. Taylor BlauAug 8, 2023
  9. Junio C HamanoAug 8, 2023
  10. Junio C HamanoAug 8, 2023
  11. Taylor BlauAug 8, 2023
  12. Derrick StoleeAug 8, 2023
  13. Taylor BlauAug 8, 2023
  14. Derrick StoleeAug 9, 2023
  15. Junio C HamanoAug 9, 2023
  16. Taylor BlauAug 9, 2023
  17. 3/6 maintenance: use random minute in Windows schedulerDerrick Stolee via GitGitGadget, Aug 7, 2023
  18. 4/6 maintenance: use random minute in cron schedulerDerrick Stolee via GitGitGadget, Aug 7, 2023
  19. 5/6 maintenance: swap method locationsDerrick Stolee via GitGitGadget, Aug 7, 2023
  20. Taylor BlauAug 7, 2023
  21. 6/6 maintenance: use random minute in systemd schedulerDerrick Stolee via GitGitGadget, Aug 7, 2023
  22. Taylor BlauAug 7, 2023
  23. Derrick StoleeAug 8, 2023
  24. Taylor BlauAug 8, 2023
  25. Phillip WoodAug 8, 2023
  26. Derrick StoleeAug 8, 2023
  27. Derrick StoleeAug 8, 2023
  28. Phillip WoodAug 9, 2023
  29. Phillip WoodAug 8, 2023
  30. Phillip WoodAug 8, 2023
  31. Derrick StoleeAug 8, 2023
  32. Derrick StoleeAug 8, 2023
  33. Phillip WoodAug 9, 2023
  34. 0/8 maintenance: schedule maintenance on a random minuteDerrick Stolee via GitGitGadget, Aug 10, 2023
  35. 1/8 maintenance: add get_random_minute()Derrick Stolee via GitGitGadget, Aug 10, 2023
  36. Taylor BlauAug 10, 2023
  37. 2/8 maintenance: use random minute in launchctl schedulerDerrick Stolee via GitGitGadget, Aug 10, 2023
  38. 4/8 maintenance: use random minute in cron schedulerDerrick Stolee via GitGitGadget, Aug 10, 2023
  39. 3/8 maintenance: use random minute in Windows schedulerDerrick Stolee via GitGitGadget, Aug 10, 2023
  40. 5/8 maintenance: swap method locationsDerrick Stolee via GitGitGadget, Aug 10, 2023
  41. 7/8 maintenance: fix systemd schedule overlapsDerrick Stolee via GitGitGadget, Aug 10, 2023
  42. Junio C HamanoAug 10, 2023
  43. Phillip WoodAug 14, 2023
  44. 6/8 maintenance: use random minute in systemd schedulerDerrick Stolee via GitGitGadget, Aug 10, 2023
  45. Phillip WoodAug 14, 2023
  46. 8/8 maintenance: update schedule before configDerrick Stolee via GitGitGadget, Aug 10, 2023
  47. Phillip WoodAug 14, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.