-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.hs
44 lines (34 loc) · 1.47 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
42
43
44
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wno-deferred-type-errors #-}
module Main where
import qualified Control.Monad as Monad
import qualified Control.Concurrent as Concurrent
import qualified Control.Exception as Exception
import qualified Database.Persist as Persist
import qualified Database.Persist.Sql as Persist
import qualified Database.Persist.Postgresql as Persist
import qualified Control.Monad.Logger as Logger
import qualified Data.ByteString as BS
import qualified Data.Pool as Pool
import Data.Time
import qualified Database.PostgreSQL.Simple as PGS
main :: IO ()
main = do
-- I started a postgres server with:
-- docker run --rm --name some-postgres -p 5432:5432 -e POSTGRES_PASSWORD=secret postgres
pool <- Pool.createPool (PGS.connect PGS.defaultConnectInfo { PGS.connectPassword = "secret" } ) PGS.close 1 10 1
threadId <- Concurrent.forkIO $ do
Pool.withResource pool $ \conn -> do
let numThings :: Int = 100000000
putStrLn $ "start inserting " <> show numThings <> " things"
Monad.forM_ [1 .. numThings] $ \_ -> do
PGS.execute_ conn "insert into foo values(1);"
putStrLn "waiting for insert thread to make progress"
Concurrent.threadDelay 5000000
Monad.void $ Concurrent.killThread threadId
putStrLn "killing insert thread"
Pool.withResource pool $ \conn -> do
PGS.execute_ conn "insert into foo values(1);"
putStrLn "done"