Skip to content

Commit

Permalink
Add 20% jitter to net worker sleep
Browse files Browse the repository at this point in the history
Avoids tightly clustered queries to the underlying database.
  • Loading branch information
scotttrinh committed Oct 23, 2024
1 parent 584795d commit 8a1aa96
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions edb/server/net_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import asyncio
import logging
import base64
import random

from edb.ir import statypes
from edb.server import defines
Expand Down Expand Up @@ -132,9 +133,10 @@ async def http(server: edbserver.BaseServer) -> None:
except Exception as ex:
logger.debug("HTTP worker failed", exc_info=ex)
finally:
await asyncio.sleep(
POLLING_INTERVAL.to_microseconds() / 1_000_000.0
jittered_polling_interval = (
POLLING_INTERVAL.to_microseconds() * random.uniform(0.8, 1.2)
)
await asyncio.sleep(jittered_polling_interval / 1_000_000.0)


@dataclasses.dataclass
Expand Down

0 comments on commit 8a1aa96

Please sign in to comment.