x
Loading
 Loading
Hello, Guest | Login | Register

A Web Server Log Database, Part Two

A small amount of code produces a logger process to write web server log entries to a database.

In last month’s “Perl of Wisdom” (available online at http://www.linux-mag.com/2006-01/perl_01, html), I showed how my Apache 2 processes use mod_perl2 to write logging information to a logger process. This month, let’s continue the discussion and look at the inner workings of the logger.

Connecting the Plumbing

The logger is launched with its stdin connected to a pipe created by the master Apache process. When the Apache master process spawns each of its child processes, the pipe is inherited by each child. Thus, each child can write information to the logger. (Conceptually, the plumbing looks something like Figure One.)

FIGURE ONE: All of the Apache server processes can write to the logger

During the logging phase, each child writes a line to the (shared) pipe that looks like:

<field1=hexvalue field2=hexvalue field3=hexvalue>

Each field name (field1, field2,…) in the string corresponds to a column in the logging database, and the hexvalues are the corresponding values.

Each server child process writes to this pipe asynchronously, without performing any sort of locking. While that sounds problematic, most modern Unix-like systems guarantee that writes under a certain size (typically 4,096 bytes) are performed atomically, so the logger process should get discrete data. To be certain, however, each record is bracketed by “& lt;& gt;”, which is easily parsed to verify that one and only one complete record was read. (In the months that I’ve been using…

Please log in to view this content.

Not Yet a Member?

Register with LinuxMagazine.com and get free access to the entire archive, including:

  • Hands-on Content
  • White Papers
  • Community Features
  • And more.
Already a Member?
Log in!
Username

Password

Remember me

Forgotten your password?
Forgotten your username?
Read More
  1. Helpful Tools for Software Developers
  2. The Github Hall of Fame
  3. Book'em, Github.
  4. This Week on Github: Stupid Ruby Tricks
  5. A Veritable Scatter Shot!
Follow Linux Magazine
Rackspace