<p></p>
<p dir="auto">Adding <code class="notranslate">sleep</code> feels a bit cargo-culty to me too. The original <a href="https://github.com/rails/rails/commit/d13623ca46c82120c398f4634e206422fc3ad7ea0">documentation in ActiveRecord</a> has been there since 2009, and the world of databases has changed a lot since then (e.g. PCIe, SSD), and even the example hinted more at a non-realistic scenario (the example uses a 50s wait between batches, in the context of people entering a club).</p>
<p dir="auto">I'm also not bothered by "CPU spikes". If the db has available CPU capacity then lets use it. So the only situation would be if the queries from the migration completes saturates the CPU (or disk IO, or networking, or similar). In this case it certainly won't, but perhaps it would happen if we e.g. did <code class="notranslate">Node.in_batches</code>. But in that case, I think <code class="notranslate">0.01</code> is a number plucked from thin air, and if the database can't handle the normal queries plus the updates, then I think backpressure from the db (i.e. these queries taking longer to complete) will regulate the migration better than arbitrary sleeps. The whole point of using batches is to give the db repeated opportunities to run other queries, it doesn't need a gap to choose the next in its queue.</p>
<p dir="auto">So my recommendation is to remove the sleep, so that the next time a contributor is looking to do something similar, they are less likely to include it in their migration too.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/5106#issuecomment-2306741639">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLOCVGZC2SCIE5BNI4DZS4BZVAVCNFSM6AAAAABM6CXMC6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBWG42DCNRTHE">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLJEATYUT25UORXNEADZS4BZVA5CNFSM6AAAAABM6CXMC6WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTUJPYKYO.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/pull/5106/c2306741639</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/5106#issuecomment-2306741639",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/5106#issuecomment-2306741639",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>