httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Akins, Brian" <Brian.Ak...@turner.com>
Subject C as config
Date Fri, 04 Jun 2010 22:21:01 GMT
All of you folks who have to answer user questions, go ahead and ready your
hate mail :)

I've been playing some with Varnish (long story) and lots of people seem to
like it.  The config "language" (VCL) is just a thin wrapper on top of C.
Heck, you can just write C inline.

Also, I do a good bit with Lua -- in httpd and other projects.  Every time I
run profiles on this stuff, Lua is always 3 out of the top 5 cpu consumers.
And lots of it is just the language itself (all the table look-ups) and we
highly optimized our method dispatches (using apr_hash, even had a version
using gperf). Now this is probably just fine for mere mortals, but it has
always bothered me.  We always meant to go back and write higher level
modules based on the "low level" Lua bindings, but we never did and we have
several non programmers who are happily writing "configs" in Lua.

As a side project several months ago (maybe I mentioned it here??), I wrote
a very simple module that basically loaded small C libraries, examined their
symbol table and added certain functions to an array for each hook:
 int fixups(request_rec *r) would get added to an array of functions ran at
fixups phase, etc.

I never really pursued it very far, but it was fast.  Of course you had all
the C things to worry about.

So, a fellow engineer and I were talking today and convinced ourselves to
strip Lua from another project and just use C as the "high level" language.
Lots of the gory implementation was already hidden in C libraries anyway, so
it was just a matter of "porting" the Lua helpers into straight C.  It took
less than 2 hours.  We were sort of shocked at the results - 1/3 the memory
usage and 50% better performance (you run out of CPU eventually, no matter
what you do).  Odd thing was, the code in C for the "Config" looked eerily
close to the Lua. Of course, that may be a good sign that I know nothing
about writing Lua... (And yes, we tested with luajit)

So, we thought about "wouldn't it just be cool if Apache had VCL."  Then I
thought, I already know C, why do I need to learn a meta-language that just
writes C???  "Won't someone think of the users!" I could here all of the
#httpd folks saying.

Not a terribly interesting read, but we are seriously considering just using
straight C with some helper functions and macros as the "config" for one of
our projects.

And, for the record I was wrong in the past - yes, async is the answer...



-- 
Brian Akins


Mime
View raw message