web development in D

Adam D. Ruppe destructionator at gmail.com
Sun May 22 17:49:49 PDT 2011


Robert Clipsham wrote:
> FastCGI has an interface available that emulates CGI - that's not
> exactly harder to implement

What scared me was that the data comes in on a socket... so wouldn't
that come with the same threading problems my simple http server
has? (Where one slow request means everyone else has to wait)

I guess I'll have to try it!

[a little later]

So I changed cgi.d to include support for fast cgi by linking in
one of the C libraries. That wasn't hard.

It was kinda painful to get the C library and apache module working
though...


Anyway, I recompiled my same in-development work application to
use fcgi, so let's run the benchmarks on it and see what we got.


Same page as I used in the last post.

7 ms per request

under regular cgi it ran in about 20 ms. My embedded httpd served
it up in 5 ms per request.

Turning up the concurrent requests to 50 (I'm using the program ab
for these benchmarks btw) shows me that Apache spawned more copies
of the process automatically. Excellent.

Got 150 ms with fcgi. 35 ms with embedded. 370 ms with plain cgi.
(I wonder why the plain cgi shows weirdness here)


With 100, my embedded one still wins by a lot in 90% of requests,
but in the other ones, it gets brutally slow - 600 ms for 5% and
9 full seconds for 1% of them. Ouch! fcgi came in at 250 for most
requests, with the longest one being a little over a second.


Getting the generated Javascript file:

-c 50, CGI: 300 ms
-c 50, FCGI: 50 ms (nice!)
-c 50, embedded: 6 ms for 95%, but one took 3 seconds.


Getting the static stylesheet, still -c 50:

CGI: 150 ms
FCGI: 50 ms
embedded: 4ms

-c 1

CGI: 12 ms
FCGI: 1 ms
embedded: 1 ms


Keep in mind, this program was *already* beating comparable mod_php
applications, even in plain CGI. Now, it's just a curbstomp.


Overall, that's pretty ok, there is a consistent boost over plain
CGI. My simple embedded server seems to do consistently better
though, until it hits the concurrency wall. (I'd be willing to bet
a big part of the reason is that the embedded one uses slices for a
lot of stuff. The other ones copy data at least once.)


Not bad at all, but I'm not sure it's good enough for me to
switch to it in general. Regardless, this proves something I've
been saying though: my cgi.d adapts with ease to different
environments.

I'm running the same program in these benchmarks. Only difference
is compiling with -version=fastcgi or -version=embedded_httpd. The
app code is completely unchanged.


More information about the Digitalmars-d-learn mailing list