The Silicon Underground
  Welcome to Dave Farquhar's Silicon Underground Friday, July 25 2008 @ 02:39 PM CDT  
Theme Changer
Change the look of the site by selecting a theme below:

What's New
STORIES
1 story in last 24 hours

COMMENTS last 48 hrs
No new comments

LINKS last 2 wks
No recent new links

Google Ads

User Functions
Username:

Password:

Don't have an account yet? Sign up as a New User

Firefox


Optimizing dynamic Linux webservers   
Monday, January 26 2004 @ 06:20 PM CST
By David L. Farquhar

Linux + Apache + MySQL + PHP (LAMP) provides an outstanding foundation for building a web server, for, essentially, the value of your time. And the advantages over static pages are fairly obvious: Just look at this web site. Users can log in and post comments without me doing anything, and content on any page can change programmatically. In my site's case, links to my most popular pages appear on the front page, and as their popularity changes, the links change.

The downside? Remember the days when people bragged about how their 66 MHz 486 was a perfectly good web server? Kiss those goodbye. For that matter, your old Pentium-120 or even your Pentium II-450 may not be good enough either. Unless you know these secrets...



First, the simple stuff. I talked about a year and a half ago about programs that optimize HTML by removing some extraneous tags and even give you a leg up on translating to cascading style sheets (CSS). That's a starting point.

Graphics are another problem. People want lots of them, and digital cameras tend to add some extraneous bloat to them. Edit them in Photoshop or another popular image editor--which you undoubtedly will--and you'll likely add another layer of bloat to them. I talked about Optimizing web graphics back in May 2002.

But what can you do on the server itself?

First, regardless of what you're using, you should be running mod_gzip in order to compress your web server's output. It works with virtually all modern web browsers, and those browsers that don't work with it negotiate with the server to get non-compressed output. My 45K front page becomes 6K when compressed, which is better than a seven-fold increase. Suddenly my 128-meg uplink becomes more than half of a T1.

I've read several places that it takes less CPU time to compress content and send it than it does to send uncompressed content. On my P2-450, that seems to definitely be the case.

Unfortunately, mod_gzip is one of the most poorly documented Unix programs I've ever seen. I complained about this nearly three years ago, and the situation seems little improved.

A simple apt-get install libapache-mod-gzip in Debian doesn't do the trick. You have to search /etc/apache/httpd.conf for the line that begins LoadModule gzip_module and uncomment it, then you have to add a few more lines. The lines to enable mod_gzip on TurboLinux didn't save me this time--for one thing, it didn't handle PHP output. For another, it didn't seem to do anything at all on my Debian box.

Charlie Sebold to the rescue. He provided the following lines that worked for him on his Debian box, and they also worked for me:

# mod_gzip settings
mod_gzip_on Yes
mod_gzip_can_negotiate Yes
mod_gzip_add_header_count Yes
mod_gzip_minimum_file_size 400
mod_gzip_maximum_file_size 0
mod_gzip_temp_dir /tmp
mod_gzip_keep_workfiles No
mod_gzip_maximum_inmem_size 100000
mod_gzip_dechunk Yes
mod_gzip_item_include handler proxy-server
mod_gzip_item_include handler cgi-script
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/postscript$
mod_gzip_item_include mime ^application/ms.*$
mod_gzip_item_include mime ^application/vnd.*$
mod_gzip_item_exclude mime ^application/x-javascript$
mod_gzip_item_exclude mime ^image/.*$
mod_gzip_item_include mime httpd/unix-directory
mod_gzip_item_include file .htm$
mod_gzip_item_include file .html$
mod_gzip_item_include file .php$
mod_gzip_item_include file .phtml$
mod_gzip_item_exclude file .css$

Gzipping anything below 400 bytes is pointless because of overhead, and Gzipping CSS and Javascript files breaks Netscape 4 part of the time.

Most of the examples I found online didn't work for me. Charlie said he had to fiddle a long time to come up with those. They may or may not work for you. I hope they do. Of course, there may be room for tweaking, depending on the nature of your site, but if they work, they're a good starting point.

Second, you can use a PHP accelerator. PHP is an interpreted language, which means that every time you run a PHP script, your server first has to translate the source code into machine language and run it. This can take longer than the output itself takes. PHP accelerators serve as a just-in-time compiler, which compiles the script and holds a copy in memory, so the next time someone accesses the page, the pre-compiled script runs. The result can sometimes be a tenfold increase in speed.

There are lots of them out there, but I settled on Ion Cube PHP Accelerator (phpa) because installation is a matter of downloading the appropriate pre-compiled binary, dumping it somewhere (I chose /usr/local/lib but you can put it anywhere you want), and adding a line to php.ini (in /etc/php4/apache on my Debian box):

zend_extension="/usr/local/lib/php_accelerator_1.3.3r2.so"

Restart Apache, and suddenly PHP scripts execute up to 10 times faster.

PHPA isn't open source and it isn't Free Software. Turck MMCache is, so if you prefer GPL, you can use it.

With mod_gzip and phpa in place and working, my web server's CPU usage rarely goes above 25 percent. Without them, three simultaneous requests from the outside world could saturate my CPU.

With them, my site still isn't quite as fast as it was in 2000 when it was just serving up static HTML, but it's awfully close. And it's doing a lot more work.

  [ Views: 1924 ]  


Optimizing dynamic Linux webservers | 1 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Optimizing dynamic Linux webservers
Authored by: keith721 on Tuesday, January 27 2004 @ 10:36 PM CST
I'm setting up a Fedora webserver in the next few weeks, and your suggestions will be invaluable in configuring things. Thanks!!!

[ Reply to This ]

What's Related
  • programs that optimize ...
  • Optimizing web graphics
  • mod_gzip
  • lines to enable mod_gzip on TurboLinux
  • Charlie Sebold
  • Ion Cube PHP Accelerator
  • Turck MMCache
  • More by DaveF
  • More from Apache

  • Story Options
  • Mail Story to a Friend
  • Printable Story Format


  • Calendar
    July 2008
    SuMoTuWeThFrSa
    29
    30
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    1
    2
    Click on any day to see postings and events for that date.

    Referrals

    Top 10 by Comments
    Story TitleComments
    Cheap laptops from Sotec 253
    An untrustworthy vendor 164
    Upgrading an eMachine 125
    eMachine upgrade advice 99
    Why I dislike Microsoft 51
    Upgrade diary: Gateway G6-400 35
    And we're live 30
    The day after the Columbia 22
    How to pray 22
    CD-ROM troubleshooting under Windows 9x 20

    Top 10 Read
    Story TitleViews
    eMachine upgrade advice 65964
    Upgrading an eMachine 56372
    How to view a blg file in Windows 2000 36051
    Cheap laptops from Sotec 28865
    Upgrade diary: Compaq Presario 7360 17503
    Upgrade diary: Gateway G6-400 16383
    CD-ROM troubleshooting under Windows 9x 13465
    Finding an open-source alternative to Ghost 11439
    Big trouble 10696
    Salary cap? Baseball needs something 10158

    Topics
    Home
    Apache (2)
    Baseball (59)
    Book reviews (2)
    Business (1)
    Christianity (57)
    Cooking (1)
    Copyright (15)
    Curmudgeonry (1)
    Design (7)
    DOS (6)
    Games (4)
    Genealogy (10)
    General (494)
    Hardware (143)
    Health (13)
    Human Interest (9)
    Humor/Satire (19)
    Journalism (1)
    Linux (92)
    Macintosh (22)
    Model Building (2)
    Music (32)
    net.culture (40)
    Personal (77)
    Photography (6)
    Retro Computing (24)
    Saving money (51)
    Servers and Networking (17)
    Society (45)
    Software (47)
    Spam (13)
    St. Louis (23)
    This weblog (14)
    Toy trains (72)
    Troubleshooting (7)
    Vendors (6)
    Video (20)
    Viruses (12)
    Windows (116)
    Writing (16)

    Older Stories
    Friday 13-Jun
  • Fathers: Give your family a gift this Father's Day weekend (0)

  • Wednesday 11-Jun
  • $13.99 a day for three days isn't $39 total! (0)
  • Registry optimization (0)

  • Tuesday 03-Jun
  • How eBay is ruining itself (0)

  • Sunday 01-Jun
  • More on Manhunt, plus revisiting Dr. Mudd (0)

  • Saturday 31-May
  • A book I've been meaning to read for a very long time (0)
  • Escape from Windows 98 (0)

  • Thursday 22-May
  • How Generation X can take this country back (1)

  • Tuesday 13-May
  • My poor-man's SSD boots DOS really fast (0)
  • One solution to the family IT man problem: Standardize (0)

  • Who's Online
    Guest Users: 4

    Syndicate!
    Get your RSS/RDF fix here.

    List of all stories
    Click here for a list of all the entries on this site


    Created this page in 0.92 seconds


     Copyright © 2008 Dave Farquhar's Silicon Underground
     All trademarks and copyrights on this page are owned by their respective owners.

    Powered by GL 1.3.x