我有以下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然而,该应用程序接口服务了大约16,000个请求,然后就“卡住”了-- ab停止并返回错误apr_socket_recv: Operation timed out (60)。
我想我误用了STM,但不确定我做错了什么。有什么建议吗?
发布于 2019-04-09 14:45:26
快速猜一猜。16,000大约是可用的TCP端口数。这可能是因为您没有关闭任何连接,因此ab的打开端口已用完
https://stackoverflow.com/questions/55586520
复制相似问题