connection-pool alternatives and similar packages
Based on the "Data" category.
Alternatively, view connection-pool alternatives based on common mentions on social networks and blogs.
-
lens
Lenses, Folds, and Traversals - Join us on web.libera.chat #haskell-lens -
semantic-source
Parsing, analyzing, and comparing source code across many languages -
text
Haskell library for space- and time-efficient operations over Unicode text. -
code-builder
Packages for defining APIs, running them, generating client code and documentation. -
compendium-client
Mu (μ) is a purely functional framework for building micro services. -
cassava
A CSV parsing and encoding library optimized for ease of use and high performance -
unordered-containers
Efficient hashing-based container types -
holmes
A reference library for constraint-solving with propagators and CDCL. -
binary
Efficient, pure binary serialisation using ByteStrings in Haskell. -
resource-pool
A high-performance striped resource pooling implementation for Haskell -
hashable
A class for types that can be converted to a hash value -
primitive
This package provides various primitive memory-related operations. -
json-autotype
Automatic Haskell type inference from JSON input -
discrimination
Fast linear time sorting and discrimination for a large class of data types -
dependent-map
Dependently-typed finite maps (partial dependent products) -
audiovisual
Extensible records, variants, structs, effects, tangles -
reflection
Reifies arbitrary Haskell terms into types that can be reflected back into terms -
dependent-sum
Dependent sums and supporting typeclasses for comparing and displaying them -
IORefCAS
A collection of different packages for CAS based data structures. -
protobuf
An implementation of Google's Protocol Buffers in Haskell. -
safecopy
An extension to Data.Serialize with built-in version control -
streaming
An optimized general monad transformer for streaming applications, with a simple prelude of functions -
bifunctors
Haskell 98 bifunctors, bifoldables and bitraversables -
orgmode-parse
Attoparsec parser combinators for parsing org-mode structured text! -
scientific
Arbitrary-precision floating-point numbers represented using scientific notation -
uuid-types
A Haskell library for creating, printing and parsing UUIDs -
text-icu
This package provides the Haskell Data.Text.ICU library, for performing complex manipulation of Unicode text.
InfluxDB - Power Real-Time Data Analytics at Scale
Do you think we are missing an alternative of connection-pool or a related project?
README
Connection Pool
Description
Connection pool is a family of specialised resource pools. Currently package provides two
- pool for TCP client connections,
- and pool for UNIX Sockets client connections.
In addition it can be used to build your own connection pool using provided primitives.
This package is built on top of resource-pool and streaming-commons. The later allows us to use conduit-extra package for implementation of TCP or UNIX Sockets clients.
Documentation
Stable releases with API documentation are available on Hackage
Examples
Simple code examples, including example from the following section, are available in [example/](example/) directory.
TCP Client Example
Here is a simple example that demonstrates how TCP client can be created and how connection pool behaves.
{-# LANGUAGE OverloadedStrings #-}
module Main (main)
where
import Control.Concurrent
( forkIO
, newEmptyMVar
, putMVar
, readMVar
, threadDelay
)
import Control.Monad (void, mapM_)
import System.Environment (getArgs)
import Control.Lens ((.~), (&))
import Data.ConnectionPool
( createTcpClientPool
, numberOfResourcesPerStripe
, numberOfStripes
, withTcpClientConnection
)
import Data.Default.Class (Default(def))
import Data.Streaming.Network (appWrite, clientSettingsTCP)
main :: IO ()
main = do
[port, numStripes, numPerStripe] <- getArgs
pool <- createTcpClientPool
(poolParams numStripes numPerStripe)
(clientSettingsTCP (read port) "127.0.0.1")
thread1 <- newEmptyMVar
thread2 <- newEmptyMVar
void . forkIO . withTcpClientConnection pool $ \appData -> do
threadDelay 1000
appWrite appData "1: I'm alive!\n"
putMVar thread1 ()
void . forkIO . withTcpClientConnection pool $ \appData -> do
appWrite appData "2: I'm alive!\n"
putMVar thread2 ()
mapM_ readMVar [thread1, thread2]
where
poolParams m n =
def & numberOfStripes .~ read m
& numberOfResourcesPerStripe .~ read n
To test it we can use socat
or some netcat
like application. Our test will
require two terminals, in one we will execute socat
as a server listenting on
UNIX socket and in the other one we execute above example.
Simple TCP server listening on port 8001
that prints what it receives to
stdout:
$ socat TCP4-LISTEN:8001,bind=127.0.0.1,fork -
The fork
parameter in the above example is important, otherwise socat
would
terminate when client closes its connection.
If we run above example as:
$ runghc tcp-example.hs 8001 1 1
We can see that socat
received following text:
1: I'm alive!
2: I'm alive!
But if we increment number of stripes or number of connections (resources) per stripe, then we will get:
2: I'm alive!
1: I'm alive!
The reason for this is that we use threadDelay 1000
in the first executed
thread. So when we have only one stripe and one connection per stripe, then we
have only one connection in the pool. Therefore when the first thread executes
and acquires a connection, then all the other threads (the other one in above
example) will block. If we have more then one connection available in our pool,
then the first thread acquires connection, blocks on threadDelay
call, but
the other thread also acquires connection and prints its output while the first
thread is still blocked on threadDelay
. This example demonstrates how
connection pool behaves if it reached its capacity and when it has enough free
resources.
License
The BSD 3-Clause License, see [LICENSE](LICENSE) file for details.
Contributions
Contributions, pull requests and bug reports are welcome! Please don't be
afraid to contact author using GitHub or by e-mail (see .cabal
file for
that).
*Note that all licence references and agreements mentioned in the connection-pool README section above
are relevant to that project's source code only.