Legend:
Library
Module
Module type
Parameter
Class
Class type
High performance lwt server
This module is an alternative to the server offered in Cohttp_lwt_unix.Server. It's a simplified implementation that has less functionality but offers more control and better performance. The differences are as follows:
Vastly improved performance due to optimized buffer handling
No dependency on conduit
No builtin logging
An example server:
open Lwt.Syntax
let server_callback ctx =
Lwt.join
[
Cohttp_server_lwt_unix.ontext.discard_body ctx;
Cohttp_server_lwt_unix.ontext.respond ctx (Http.Response.make ())
(Cohttp_server_lwt_unix.Body.string "hello world");
]
let main () =
let* _server =
let listen_address = Unix.(ADDR_INET (inet_addr_loopback, 8080)) in
let server = Cohttp_server_lwt_unix.create server_callback in
Lwt_io.establish_server_with_client_address ~backlog:10_000
listen_address (fun _addr ch ->
Cohttp_server_lwt_unix.handle_connection server ch)
in
let forever, _ = Lwt.wait () in
forever
let () = ignore (Lwt_main.run (main ()))