繁体   English   中英

使用STM“卡住”

[英]Getting “stuck” using STM

我有以下Scotty应用,尝试使用STM来保持服务的API调用计数:

{-# LANGUAGE OverloadedStrings #-}

module Main where

import Web.Scotty
import Data.Monoid (mconcat)
import Control.Concurrent.STM
import Control.Monad.IO.Class

main :: IO ()
main = do
  counter <- newTVarIO 0
  scotty 3000 $
    get "/:word" $ do
      liftIO $ atomically $ do
        counter' <- readTVar counter
        writeTVar counter (counter' + 1)
      liftIO $ do
        counter' <- atomically (readTVar counter)
        print counter'
      beam <- param "word"
      html $ mconcat ["<h1>Scotty, ", beam, " me up!</h1>"]

我像这样“测试” API:

ab -c 100 -n 100000 http://127.0.0.1:3000/z

但是,该API提供大致约16000请求,然后被“卡住” - ab停止与错误apr_socket_recv: Operation timed out (60)

我认为我滥用STM,但不确定自己做错了什么。 有什么建议么?

在这里快速猜测。 16,000大约是可用的TCP端口数。 是否可能您没有关闭任何连接,因此用完了ab的开放端口?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM