[Haskell-beginners] Warp and Yesod benchmark puzzle

Felipe Almeida Lessa felipe.lessa at gmail.com
Sat Sep 1 16:20:06 CEST 2012


On Sat, Sep 1, 2012 at 6:33 AM, Krzysztof Skrzętnicki <gtener at gmail.com> wrote:
> makeSessionBackend calls "getKey" from clientsession:
>
> http://hackage.haskell.org/packages/archive/clientsession/0.8.0/doc/html/src/Web-ClientSession.html#getKey
>
> Looking at that function no wonder it is a bottleneck:
>
> -- | Get a key from the given text file.
> --
> -- If the file does not exist or is corrupted a random key will
> -- be generated and stored in that file.
> getKey :: FilePath     -- ^ File name where key is stored.
>        -> IO Key       -- ^ The actual key.
> getKey keyFile = do
>     exists <- doesFileExist keyFile
>     if exists
>         then S.readFile keyFile >>= either (const newKey) return . initKey
>         else newKey
>   where
>     newKey = do
>         (bs, key') <- randomKey
>         S.writeFile keyFile bs
>         return key'
>
>
> Plenty of syscalls, reading and parsing the same file over and over again.
> Perhaps the default should be to store the key within the foundation
> datatype at startup?

Unfortunately it's not so simple: makeSessionBackend is called just
once by 'toWaiAppPlain', which is in turn called just once when your
application starts.

Cheers, =)

-- 
Felipe.



More information about the Beginners mailing list