Skip to content

Commit

Permalink
pollBatch: wait 100ms for the write to complete
Browse files Browse the repository at this point in the history
Summary:
We're incurring a minimum 1s delay for every write currently, because
the first poll will always fail and the caller (often SendQueue.hs)
waits 1s before polling again.

This makes tests run slowly, in particular.

Workaround: block for max 100ms in pollBatch to allow writes that
complete quickly to avoid the poll/retry roundtrip.

Reviewed By: donsbot

Differential Revision: D51206446

fbshipit-source-id: 8faa5d609cd586c0fd3f5c9b789289561c482307
  • Loading branch information
Simon Marlow authored and facebook-github-bot committed Nov 13, 2023
1 parent 9b72960 commit a54f054
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion glean/db/Glean/Database/Writes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import qualified Data.Text.Encoding as Text
import qualified Data.UUID as UUID
import qualified Data.UUID.V4 as UUID
import System.Clock
import System.Timeout

import ServiceData.GlobalStats
import ServiceData.Types
Expand Down Expand Up @@ -319,7 +320,11 @@ pollBatch env@Env{..} handle = do
r <- HashMap.lookup handle <$> readTVarIO envWrites
case r of
Just write -> do
s <- tryReadMVar (writeWait write)
-- for tiny writes that will complete in a few ms, we would like
-- to wait synchronously. Otherwise we'll return a Retry to the
-- caller which will wait 1s before polling again. In particular
-- all those one-second delays make tests run slowly.
s <- timeout 100000 $ readMVar (writeWait write)
case s of
Just x -> do
atomically $ void $ updateTVar envWrites $ HashMap.delete handle
Expand Down

0 comments on commit a54f054

Please sign in to comment.