2019-02-11 18:43:16 +01:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
|
|
|
{-# LANGUAGE DeriveGeneric #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE PolyKinds #-}
|
|
|
|
{-# LANGUAGE TypeFamilies #-}
|
|
|
|
{-# LANGUAGE TypeOperators #-}
|
2016-05-13 16:15:03 +02:00
|
|
|
module Main (main) where
|
|
|
|
|
|
|
|
import Data.Text (Text)
|
|
|
|
import Network.Wai (Application)
|
|
|
|
import Network.Wai.Handler.Warp
|
|
|
|
import Servant
|
|
|
|
import Servant.Ekg
|
|
|
|
import System.Metrics
|
|
|
|
import System.Process
|
|
|
|
|
|
|
|
|
|
|
|
type BenchApi = "hello" :> Capture "name" Text :> Get '[JSON] Text
|
|
|
|
|
|
|
|
benchApi :: Proxy BenchApi
|
|
|
|
benchApi = Proxy
|
|
|
|
|
|
|
|
server :: Server BenchApi
|
|
|
|
server = return
|
|
|
|
|
|
|
|
servantEkgServer :: IO Application
|
|
|
|
servantEkgServer = do
|
2019-02-11 18:43:16 +01:00
|
|
|
mware <- monitorEndpoints benchApi =<< newStore
|
|
|
|
|
|
|
|
return $ mware (serve benchApi server)
|
2016-05-13 16:15:03 +02:00
|
|
|
|
|
|
|
benchApp :: IO Application -> IO ()
|
|
|
|
benchApp app = withApplication app $ \port ->
|
2016-05-13 17:38:14 +02:00
|
|
|
callCommand $ "wrk -c 30 -d 20s --latency -s bench/wrk.lua -t 2 'http://localhost:" ++ show port ++ "'"
|
2016-05-13 16:15:03 +02:00
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
|
|
|
putStrLn "Benchmarking servant-ekg"
|
|
|
|
benchApp servantEkgServer
|
|
|
|
putStrLn "Benchmarking without servant-ekg"
|
|
|
|
benchApp . return $ serve benchApi server
|