当我 运行 很多并行的 http 请求时,我得到 "no such protocol name: tcp"

When I run a lot of http requests in parallel, I get "no such protocol name: tcp"

代码

mapConcurrently httpLBS requests

投掷

ConnectionFailure Network.BSD.getProtocolByName: does not exist (no such protocol name: tcp))

大约 1k 个请求后。

所有请求都是 运行 并行的,并且使进程 运行 超出了文件描述符。使用

import ClassyPrelude

traverseThrottled :: (MonadMask m, MonadBaseControl IO m, Forall (Pure m), Traversable t) => Int -> (a -> m b) -> t a -> m (t b)
traverseThrottled concLevel action taskContainer = do
    sem <- newQSem concLevel
    let throttledAction = bracket_ (waitQSem sem) (signalQSem sem) . action
    mapConcurrently throttledAction taskContainer

(如果不使用 ClassyPrelude,请调整导入)

如果您使用流式传输替代方案,请确保您的 httpLBS 等价物使用请求。而且你的 b 在所有领域都很严格。