当我并行运行大量http请求时,我得到“没有这样的协议名称:tcp”

时间:2017-11-06 19:34:25

标签: haskell http-conduit

代码

mapConcurrently httpLBS requests

引发

ConnectionFailure Network.BSD.getProtocolByName: does not exist (no such protocol name: tcp))
在大约1k的请求之后

1 个答案:

答案 0 :(得分:5)

请求全部并行运行,并使进程耗尽文件描述符。使用

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在所有领域都是严格的。