[Haskell-cafe] Happstack: serveDirectory vs serveFile
Jeremy Shaw
jeremy at n-heptane.com
Fri Jan 23 22:46:09 UTC 2015
Hello!
Underneath the hood, they are both using the same function to actually
serve the file. There are a few reasons why serveDirectory might appear to
be faster.
The first thing to double check is that both serveDirectory and serveFile
are returning 200 OK, and not 404. You want to confirm that the file really
is being transferred in both cases.
Given that favicon.ico is likely a small file, the time spent processing
requests could be dominated by some other seemingly insignificant factor.
Since serveDirectory is listed first, it is going to have a slight
advantage, because the routes are tried in order. If you switch the order
and list serveFile first do you see any change in performance?
Additionally, in this code you could get away with using 'dir' instead of
'dirs' since you do not have any '/' in the path. Because 'dirs' has to
look for the '/', it is going to take longer to search 'favicon.ico' than
'hehe' -- which would also give a slightly advantage to the serveDirectory
branch.
You are correct in expecting that serveFile should be faster than
serveDirectory since it is supposed to do less. But microbenchmarks like
this can easily be dominated by unrelated factors.
- jeremy
On Fri, Jan 23, 2015 at 10:09 AM, Semen Trygubenko / Семен Тригубенко <
semen at trygub.com> wrote:
> Dear all,
>
> I've ran a simple benchmark where two serve functions
> were side-by-side in an msum and looked like
>
> dirs "hehe" $ serveDirectory DisableBrowsing [] "/hehe"
> dirs "favicon.ico" $ serveFile (asContentType "image/x-icon") "favicon.ico"
>
> "hehe" directory also contained file "favicon.ico".
>
> This is happstack server version 7.3.9.
>
> I've been hammering it with ab and confirmed this puzzling result:
> it seems that serveFile route is approximately
> two orders of magnitude slower than serveDirectory route...
>
> Will be grateful for any clues as to what I'm doing wrong!
>
> Thanks,
> S.
>
>
> --
> Семен Тригубенко http://trygub.com
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20150123/cb850894/attachment.html>
More information about the Haskell-Cafe
mailing list