Permalink
Browse files

Get connection pool options from config file. Bump unordered-containers

dependency.
  • Loading branch information...
1 parent 6c768d7 commit cf5b75ed8a6c5b027ddf0ef25b99fcb8515b8417 @mightybyte committed Apr 23, 2012
Showing with 18 additions and 2 deletions.
  1. +12 −0 resources/db/devel.cfg
  2. +1 −1 snaplet-postgresql-simple.cabal
  3. +5 −1 src/Snap/Snaplet/PostgresqlSimple.hs
View
12 resources/db/devel.cfg
@@ -3,3 +3,15 @@ port = 5432
user = "postgres"
pass = ""
db = "testdb"
+
+# Nmuber of distinct connection pools to maintain. The smallest acceptable
+# value is 1.
+numStripes = 1
+
+# Number of seconds an unused resource is kept open. The smallest acceptable
+# value is 0.5 seconds.
+idleTime = 5
+
+# Maximum number of resources to keep open per stripe. The smallest
+# acceptable value is 1.
+maxResourcesPerStripe = 20
View
2 snaplet-postgresql-simple.cabal
@@ -44,7 +44,7 @@ Library
snap >= 0.9 && < 0.10,
text >= 0.11 && < 0.12,
transformers >= 0.2 && < 0.3,
- unordered-containers >= 0.1.4 && < 0.2
+ unordered-containers >= 0.2 && < 0.3
ghc-options: -Wall -fwarn-tabs -funbox-strict-fields
View
6 src/Snap/Snaplet/PostgresqlSimple.hs
@@ -171,7 +171,11 @@ pgsInit = makeSnaplet "postgresql-simple" description datadir $ do
return $ P.ConnectInfo <$> host <*> port <*> user <*> pwd <*> db
let ci = fromMaybe (error $ intercalate "\n" errs) mci
- pool <- liftIO $ createPool (P.connect ci) P.close 1 5 20
+ stripes <- liftIO $ C.lookupDefault 1 config "numStripes"
+ idle <- liftIO $ C.lookupDefault 5 config "idleTime"
+ resources <- liftIO $ C.lookupDefault 20 config "maxResourcesPerStripe"
+ pool <- liftIO $ createPool (P.connect ci) P.close stripes
+ (realToFrac (idle :: Double)) resources
return $ Postgres pool
where
description = "PostgreSQL abstraction"

0 comments on commit cf5b75e

Please sign in to comment.