c10k-0.4.0: C10k server library using prefork

Network.C10kServer

Description

Network server library to handle over 10,000 connections. Since GHC 6.12 or earlier uses select(), it cannot handle connections over 1,024. This library uses the "prefork" technique to get over the barrier. Each process handles threadNumberPerProcess connections. preforkProcessNumber child server processes are preforked. So, this server can handle preforkProcessNumber * threadNumberPerProcess connections.

Programs complied by GHC 6.10 or earlier with the -threaded option kill the IO thread when forkProcess is used. So, don't specify the -threaded option to use this library.

Even if GHC 6.14 supports kqueue or epoll(), it is difficult for RTS to balance over multi-cores. So, this library can be used to make a process for each core and to set limitation of the number to accept connections.

To stop all server, send SIGTERM to the parent process. (e.g. kill `cat PIDFILE` where the PID file name is specified by pidFile)

Synopsis

Documentation

data C10kConfig Source

The type of configuration given to runC10kServer as the second argument.

Constructors

C10kConfig 

Fields

initHook :: IO ()

A hook called initialization time. This is used topically to initialize syslog.

exitHook :: String -> IO ()

A hook called when the server exits due to an error.

parentStartedHook :: IO ()

A hook to be called in the parent process when all child process are preforked successfully.

startedHook :: IO ()

A hook to be called when each child process is started successfully.

sleepTimer :: Int

The time in seconds that a main thread of each child process to sleep when the number of connection reaches threadNumberPerProcess.

preforkProcessNumber :: Int

The number of child process.

threadNumberPerProcess :: Int

The number of thread which a process handle.

portName :: ServiceName

A port name. e.g. "http" or "80"

ipAddr :: Maybe HostName

A numeric IP address. e.g. "127.0.0.1"

pidFile :: FilePath

A file where the process ID of the parent process is written.

user :: String

A user name. When the program linked with this library runs in the root privilege, set user to this value. Otherwise, this value is ignored.

group :: String

A group name. When the program linked with this library runs in the root privilege, set group to this value. Otherwise, this value is ignored.

type C10kServer = Socket -> IO ()Source

The type of the first argument of runC10kServer.

type C10kServerH = Handle -> TCPInfo -> IO ()Source

The type of the first argument of runC10kServerH.