jump to navigation

The Golden Wombat of Destiny 2008.03.15

Posted by nathany in mod_wombat.
Tags: , , , ,
add a comment

The Golden Wombat of Destiny was a text adventure game (interactive fiction) written by Huw Collingbourne in early `80s. I honestly never got very far in that game, preferring Colossal Cave and The Hitchhiker’s Guide to the Galaxy in the days of the Kaypro IV.

Today we’re going to talk about a different wombat, with a different destiny.

Spear-headed by Brian McCallister, mod_wombat embeds the Lua programming language into the Apache HTTP server in the same fashion as mod_perl, mod_php and mod_python bring their respective languages into the Apache world of web development.

How mod_wombat differs has a lot to do with how Lua differs from other languages. Lua is a very lightweight scripting language originally designed for non-programmers to customize the software it is embedded in. It is simple to pick up, while offering a good amount of flexibility and power. Its popularity in game scripting has pushed its’ interpreter towards being very efficient and multi-thread ready.

Apache is the heavy-weight champion of HTTP servers, responsible for serving up half the Internet. Apache 2.x was a substantial reworking, providing:

  • The Apache Portable Runtime (APR) so Module writers don’t need to deal with all the OS-specific issues.
  • Swappable multi-processing modules (MPMs) including Prefork (non-threaded), Worker threads, and an Event MPM that decouples server threads from the HTTP connection (read: very efficient).

Lua is designed for embedding in C-based programs, which allows mod_wombat to take advantage of the substantial infrastructure Apache provides. More than any other language module, mod_wombat endeavors to work with Apache.

Matthew Burke is looking for students to work on mod_wombat as part of the 2008 Google Summer of Code. If you are a student who is interested, you should definitely get in touch with Matthew Burke and Brian McCallister to discuss your ideas. Who knows, this could be your destiny? :-)

This is gonna be great

Lua atop Apache could make for a very sweet development platform for web applications, both large and small.

  • Lua is simpler than other scripting languages used for web development, making it easy to pick-up. This is exemplified by the use of tables as a universal data structure (like PHP Arrays, but unlike Python or Ruby).
  • Lua has several commonalities with JavaScript, like first-class functions, closures, and prototype-based object orientation. Yet it steps beyond most languages with proper tail calls and coroutines.
  • There is a fairly clean slate to start with, meaning it doesn’t carry the baggage of hundreds of procedural methods like PHP, or code mixed into HTML templates. APIs can be nicely organized and designed for simplicity (i.e. ColdFusion’s DateFormat and TimeFormat make it easier to reason about date formatting than Ruby or PHP’s methods).
  • Apache’s efficient threading modules combined with Lua’s low-overhead and thread-safety make for a very performant platform. That means it is able to handle a load of traffic without a huge hardware investment.
  • Deploying with an Apache module is often the preferred method, as opposed to more complicated reverse proxy setups or FastCGI. For ease of deployment, this is an advantage over the popular Ruby platform, which has no true mod_ruby.
  • The mod_wombat project was started by Apache Software Foundation members, is hosted with Apache, and has their backing as a supported module for Apache users.

Ideas

If you are a student joining the GSoC, you will need to come up with your own proposal. I’m not a student, so I don’t qualify, but I will post here a few of the basic ideas that I believe are of general consensus.

Simplify installation

For mod_wombat to become a platform of choice, it needs to be dead-simple to deploy, whether as a development environment or a production server. This would be served by relying only on those modules included with the Apache distribution.

There has been a desire to remove the dependency on libapreg2, which is used to parse HTTP cookies, query-strings and POST data. The required functionality would need to be incorporated into mod_wombat directly.

Tighter integration with Apache HTTP Server 2.2

There is a lot that can be done to further integrate Lua with Apache, whether using Lua to configure Apache, or to pull Apache functionality into Lua.

Perhaps the most significant and obvious, would be integration with Apache’s Database Framework. With DBD, the database drivers for your web application are bundled with Apache, and Apache manages a pool of database connections in an intelligent way appropriate for the MPM being used. With mod_wombat, Lua could be the first language to really take advantage of this feature, new to Apache 2.2.

Write something with it

What mod_wombat provides is an API to higher-level web frameworks and applications. It’s hard to know how those APIs should be written without using them. Building a small project atop mod_wombat could go a long way in designing a concise and friendly API.

Preferably using some sort of code standards.

Resources

If you choose to partake in this endeavor, there a few things you must know.

  • Working knowledge of ANSI C, perhaps C: A Reference Manual will help.
  • Programming in Lua is an excellent resource for both the Lua programming language and how to interface it with C.
  • The Apache Modules Book goes over Apache’s architecture and writing Modules for it, including a chapter on DBD.
  • A willingness to work with autoconf and related build tools. There is but one book dedicated to the subject, and the online version is more up-to-date.
  • Familiarity with existing web development environments and experience with database systems.
  • An understanding of just how Google Summer of Code works.
  • Go through Brian’s slides and download the source code from Subversion to familiarize yourself with mod_wombat.

And that’s all there’s to it. Ready to get coding?

Follow-up

Maxime Petazzoni has accepted the role of working on mod_wombat for GSoC this year. See the Apache mailing list.

Lua and the web: an overview 2008.03.15

Posted by nathany in Lua.
Tags: , , , ,
2 comments

Lua is among the top 20 most popular programming languages, according to the TIOBE Programming Community index. Lua is also faster and has a smaller memory footprint than other interpreted scripting languages (compare with Ruby, Python, PHP and JavaScript SpiderMonkey).

We haven’t heard a lot about Lua on the web, even though
there are a number of developers working with Lua on the server-side. Lets take a brief look.

The Kepler Project

Kepler is a “web development platform” named after astronomer Johannes Kepler. It looks to be the most ambitious project of the bunch. Kepler is written as a number of modules that fit together, and includes its’ own web server named Xavante.

There is also an endeavor to build WSAPI, in similar fashion to
Python’s WSGI interface, that support pretty much any web server and configuration (CGI, FastCGI, SCGI, etc, etc.)

Nanoki

When I joined to Kepler mailing list, “Petite Abeille” was the first person to respond. He has been developing a Wiki called Nanoki.

However, it is not built on top of Kepler. Instead there is a small built-in web server or will run atop the Unix tcp command. All the source code is released under a MIT license, and is instructive in building a light, focussed web application vs. the broad scope of Kepler.

mod_wombat

Brian McCallister spear-headed a project to embed Lua in an Apache HTTP Server module. Going through Brian’s slides is quite inspiring as to just how good a fit this is. Apache does all the heavy-lifting, such as providing a fully multi-threaded “worker MPM” (multi-processing module) and a portable runtime (APR) environment. Lua is a thread-safe language, with “share-nothing” Lua states, so it fits right in and is super-efficient.

Skimming through The Apache Modules Book is even more inspiring, as you can see the potential of mod_wombat if it took advantage of Apache’s database connection pooling (DBD) and the various other facilities of Apache HTTP Server.

Wombat is still a little rough around the edges, but you can find the Apache-licensed source code at:
http://svn.apache.org/repos/asf/httpd/mod_wombat/trunk.

Launch: getting Lua installed 2007.11.10

Posted by nathany in Lua.
Tags: , ,
3 comments

To play with Lua you need to download the source code and compile it. This isn’t as scary as it sounds, as Lua is a positively tiny download and doesn’t depend on anything more than a C compiler. Lua is written in standard ANSI C, so any one should work. I will give instructions for Mac OS X, because that’s what I use.

Building

First, you need to have Apple’s Developer Tools installed. They should be your Mac OS X disc, under Optional Installs -> Xcode Tools. Run the XcodeTools package to install. You can also download Xcode if you sign up for a free ADC account (but note: they are large!).

Next, download Lua source code and unpack the archive in Finder. Or you can use Terminal to download the current release (5.1.2) to your Downloads folder (or a suitable location of your choice):

cd Downloads
curl -O http://www.lua.org/ftp/lua-5.1.2.tar.gz
tar xzvf lua-5.1.2.tar.gz
cd lua-5.1.2

Either way, you need Terminal (from Application/Utilities) to do the rest. Make sure you are in the lua-5.1.2/ folder, and type:
make macosx

Several lines should scroll by. On Leopard you will see some deprecated warnings in loadlib.c. Don’t worry about it. To make sure everything is okay, run:
make test
You should see “Hello world, from Lua 5.1!”

Installing

It is possible to run the Lua interpreter from right here, but let’s install it the rest of the way. For this we will need to run “make install”. By default Lua installs to /usr. This will work, but it’s recommended to install under /usr/local.

So from the lua-5.1.2/ folder, run:
sudo make install INSTALL_TOP=/usr/local
and provide your password.

It appears that Leopard ships with /usr/local/bin in your path. You can check by running: (make sure PATH is uppercase)
env | grep PATH

If you don’t see it there, you need to modify your .profile file.
pico ~/.profile

and include:

export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
export MANPATH=”/usr/local/man:$MANPATH”

If you are using TextMate, and will be installing the Lua bundle later, you may also want to include:

export SVN_EDITOR="mate -w"
export LC_CTYPE=en_US.UTF-8

With pico, press Ctrl-X followed by Y to exit and save.

The changes will take affect when you open a new Terminal window.

Running

With Lua installed in your path, you can run it in Terminal from any folder. Just type:
lua

This brings up the interactive interpreter. You can type in Lua code:
print "Hi"
= 2 + 3

Press Ctrl-C to exit when you’re done.

Now that Lua is installed, you could remove the Downloads/lua-5.1.2 folder. But you may want to check out the test/ folder for some example code. You can run these examples from within the lua-5.1.2/test/ folder like this:

lua factorial.lua

A local copy of the Reference Manual can be found under doc/manual.html.

TextMate

If you are using TextMate, there is a Lua bundle to give it color syntax highlighting and a few snippets. Unfortunately the Lua bundle isn’t included by default. You can either use GetBundle, or you can grab it with the command line as follows.

The bundles are stored in a Subversion repository, which requires Subversion (svn) on your computer. Leopard comes with Subversion, but for Tiger or prior you need to install it. I’ve had good success with Martin Ott’s Subversion package.

As per the TextMate manual:

mkdir -p /Library/Application\ Support/TextMate/Bundles
cd /Library/Application\ Support/TextMate/Bundles
svn co http://macromates.com/svn/Bundles/trunk/Bundles/Lua.tmbundle

You need to restart TextMate or navigate to to Bundles -> Bundle Editor -> Reload Bundles in the menu.

Files with a .lua extension will be associated with the Lua language bundle. One nice feature is that you can press Command-R to run them.

So that’s about it for getting setup. Now we just need to write some code!