@@ -4,6 +4,7 @@
44module Network.Wai.Handler.Warp.Run where
55
66import Control.Concurrent (threadDelay, forkIOWithUnmask)
7+import qualified Control.Concurrent as Conc (yield)
78import Control.Exception
89import qualified Control.Exception.Lifted as Lifted
910import Control.Monad (forever, when, unless, void)
@@ -256,6 +257,15 @@ serveConnection timeoutHandle settings cleaner app conn remoteHost' =
256257 liftIO $ T.resume th
257258 sendResponse settings cleaner env' conn res
258259
260+ -- | We just send a Response and it takes a time to
261+ -- receive a Request again. If we immediately call recv,
262+ -- it is likely to fail and the IO manager works.
263+ -- It is very costy. So, we yield to another Haskell
264+ -- thread hoping that the next Request will arraive
265+ -- when this Haskell thread will be re-scheduled.
266+ -- This improves performance at least when
267+ -- the number of cores is small.
268+ Conc.yield
259269 -- flush the rest of the request body
260270 requestBody env $$ CL.sinkNull
261271 ResumableSource fromClient' _ <- liftIO getSource