I want to test performance (request per sec) of haskell warp http server. I don’t know anything about haskell. I want to do the same as in erlang code below:
- load “page.txt” only once from disk (ascii file 100kB)
- serve contents of that file on every request but without reloading it from disk
How to do this in haskell?
Erlang:
-module(test).
-export([start/0]).
start() ->
{ok, Bin} = file:read_file("page.txt"),
misultin:start_link([{port, 3000}, {loop, fun(Req) -> Req:ok(Bin) end}]).
I came across this haskell example and i need to modified it to use contents loaded from a file.
Haskell:
{-# LANGUAGE OverloadedStrings #-}
import Network.Wai
import Network.Wai.Handler.Warp
import Blaze.ByteString.Builder (fromByteString)
import Network.HTTP.Types (status200)
main = run 3000 $ const $ return $ ResponseBuilder
status200
[("Content-Type", "text/plain"), ("Content-Length", "4")]
$ fromByteString "TEST"
Please help! 🙂
Read the contents of the file as a strict
ByteStringusinghGetContentsfromData.ByteString, then pass it to Blaze’sfromByteString:I didn’t get it to work with relative paths on Windows, but that might just be my lack of Haskell-fu.