代码之家  ›  专栏  ›  技术社区  ›  Reactormonk

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

  •  2
  • Reactormonk  · 技术社区  · 9 年前

    代码

    mapConcurrently httpLBS requests
    

    投掷

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

    大约1k次请求后。

    1 回复  |  直到 9 年前
        1
  •  5
  •   Reactormonk    9 年前

    这些请求都是并行运行的,使进程用光了文件描述符。使用

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

    推荐文章