forked from christian-marie/servant-ekg
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathMain.hs
41 lines (32 loc) · 1.15 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
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
mware <- monitorEndpoints benchApi =<< newStore
return $ mware (serve benchApi server)
benchApp :: IO Application -> IO ()
benchApp app = withApplication app $ \port ->
callCommand $ "wrk -c 30 -d 20s --latency -s bench/wrk.lua -t 2 'http://localhost:" ++ show port ++ "'"
main :: IO ()
main = do
putStrLn "Benchmarking servant-ekg"
benchApp servantEkgServer
putStrLn "Benchmarking without servant-ekg"
benchApp . return $ serve benchApi server