BlogMatrix
 

No BlogMatrix Platform on Windows

edit David P. Janes 2007-08-12 12:09 UTC add comment  ·  ·  ·

I think it may be doable, but it's quite a time sink. We're leave all our mods in the code base for another day but the core issue is that the Windows "shortcut" is a third-class citizen compared to UNIX's symbolic link. And we use a lot of symbolic links, especially when constructing the "htdocs" directory for Apache. Now, in Python we can get around this (not efficiently, but good enough) but Apache just doesn't have the proper code to do this. The other option would be to run it all under Cygwin, except mod_python isn't really supported and that's a whole other can of worms.

Running mod_python on Windows XP

edit David P. Janes 2007-08-10 18:13 UTC add comment  ·  ·  ·

I'm currently linuxless, but since I have access to a Windows XP laptop I thought I'd try a few little experiments. I'm probably not going to pursue this to far, as at this stage in the game it doesn't make a lot of sense to bring another, radically different, platform into the mix.

Running mod_python on Windows (XP) is actually quite simple:

On Windows I find it fairly useful to install everything the default way. Configuring this is simplicity:

  • edit httpd.conf (there's probably a start menu option for this)
  • add "LoadModule python_module modules/mod_python.so" in the LoadModules section
  • restart Apache
  • test (the Directory version works out of the box with the appropriate path adjustment)

BlogMatrix uses a lot of shell scripts; mixing this together with Windows Python (not Cygwin Python) is going to be a challenge, as the way paths are handled is different.

Apache mod_deflate problem solved

edit David P. Janes 2007-05-07 12:17 UTC 4 comments  ·

We are trying to serve some of our overlarge Javascript programs using mod_deflate to reduce network traffic and hopefully speed up load times on your end. This could potentially make a lot of difference.

Normal:

$ curl http://semantic.xxx.org/:root/packed/MochiKit_standard.js --head
HTTP/1.1 200 OK
Date: Mon, 07 May 2007 12:09:02 GMT
Server: Apache/2.0.59 (Unix) DAV/2 mod_python/3.2.10 Python/2.4.4
Last-Modified: Sun, 06 May 2007 11:58:48 GMT
ETag: "bf4172-3659a-e83cae00"
Accept-Ranges: bytes
Content-Length: 222618
Vary: Accept-Encoding
Connection: close
Content-Type: application/x-javascript

Compressed:

$ curl http://semantic.xxx.org/:root/packed/MochiKit_standard.js --compressed --head
HTTP/1.1 200 OK
Date: Mon, 07 May 2007 12:08:50 GMT
Server: Apache/2.0.59 (Unix) DAV/2 mod_python/3.2.10 Python/2.4.4
Last-Modified: Sun, 06 May 2007 11:58:48 GMT
ETag: "bf4172-3659a-e83cae00"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 55248
Connection: close
Content-Type: application/x-javascript

But unfortunately, we couldn't start Apache because we were getting the following error:

actl semantic/semantic start
Syntax error on line 862 of /usr/blogmatrix/apache/semantic/semantic/conf/httpd.conf:
Cannot load /usr/blogmatrix/apache/semantic/semantic/modules/mod_deflate.so into server:
/usr/blogmatrix/apache/semantic/semantic/modules/mod_deflate.so: undefined symbol: deflate

The solution turns out to be fairly simple -- just add LoadFile for zlib into the apache conf

LoadFile /usr/lib/libz.so
LoadModule deflate_module modules/mod_deflate.so
AddOutputFilterByType DEFLATE application/x-javascript text/javascript text/css

Apache, mod_python and XML don't play well together

edit David P. Janes 2006-09-28 14:07 UTC add comment  ·  ·  ·  ·  ·  ·

We have a really neat demo of importing microformats into BlogMatrix. However, we can't show you. Why?

We'll have to recompile Apache against Python's Expat and go from there. This will cause a short period of downtime, so we won't be doing this for a little while yet.

Wednesday Morning Notes

edit David P. Janes 2006-08-30 11:57 UTC add comment  ·  ·  ·  ·  ·

There's a few more updates this morning:

  • We've added a "Text Gadget", so you can add your own arbitrary text to the sidebar. If you go to your admin page and then to your Profile, you will get instructions use this.
  • You can now control your comments (from your Profile). Your options are:
    • accept all comments, display immediately
    • accept all comments, but they must be approved before posting
    • don't accept comments
  • On a technical note, we've upgraded to mod_python 3.2.10 and we're using FileSession to manage sessions (which should cut a few tenths of seconds of page loading time).

Using Amazon S3 to serve static files

edit David P. Janes 2006-08-06 12:11 UTC 2 comments  ·  ·  ·  ·  ·

The V10 look and feel (i.e. what you're seeing here) uses a substantial number of GIF files to achieve the candy-like "web 2.0" look. Additionally since we're using a fair number of javascript include libraries (MochiKit, TinyMCE, Yahoo UI), what we're ending up is a lot of trips to our server the first time a user sees a page.

This equals unnecessary slowness and page response time. What I'd like to do is speed this up a little (or maybe a lot) by offloading serving these mostly static files. Right now I'm experimenting with Amazon S3 and I'll document what I'm doing.

I'm not breaking any ground here: Adrian Holovaty did this first to offload pages from Chicago Crime and has documented his experiences. I'm just going to expand and annotate what he wrote (the blockquoted italics text is his):

It was easy to get this working; took less than an hour total. Here's what I did:

First, I signed up for an Amazon S3 account. Do that by clicking "Sign Up For Web Service" on the main S3 page. When you sign up, you get two codes: an access key ID and secret access key.

You'll need to provide a credit card to pay for your (as-you-use-it) Amazon S3 services. You have to click on a provided link to get the keys. There's a X.509 certificate (rather than secret key) way of accessing your S3 account but it only works with SOAP and I'd rather stick a fork in my eye and wiggle it around first. Moving right along...

Next, I created an S3 "bucket" for my chicagocrime.org media files. An account can have multiple buckets. As far as I can tell, it's just a way of keeping your S3 stuff in separate containers. I did this by using the free S3 Python bindings. Just download the file, unzip it and put the file S3.py somewhere on your Python path. To create a bucket named 'mybucketname', do this:

import S3
conn = S3.AWSAuthConnection('your access key', 'your secret key')
conn.create_bucket('mybucketname')

I found it easier just to distutil S3.py into my standard Python library:

from distutils.core import setup
setup(
        name='S3',
        version='20060805',
        py_modules=['S3'],
)

I created a bucket called 'semantic.blogmatrix.com'

Next, I wrote a Python script that uploaded my media files to this bucket and made them publically readable. S3 has a bunch of complex authentication stuff, but all I wanted to do was use S3, essentially, as a Web hosting service. Here's the script I used, and here's how to use it:

cd /directory/with/media/files/



find | python /path/to/update_s3.py

The script is kind of cool because it uses Python's mimetypes to determine the content type of each file in order to pass that to the S3 API. Otherwise it's pretty straightforward.

I've written my own little program (attached) to do this which takes care of all the path searching, etc.. I'll probably modify it some more to track what it's uploaded so we don't multiple upload files. Here's the help:

blogmatrix.v10@s002. python S3Uploader.py --help
usage: S3Uploader.py [options]

options:
  -h, --help            show this help message and exit
  --debug              
  --bucket=BUCKET       Amazon S3 Bucket
  --access-key=ACCESS_KEY
                        Amazon S3 Access Key (required)
  --secret-key=SECRET_KEY
                        Amazon S3 Secret Access Key (command line prompt if
                        missing)
  --root=ROOT           All directories are made relative to this (optional)
                        root
  --directory=DIRECTORIES
                        Upload files from this directory (default: .)
  --extension=EXTENSIONS
                        Upload files matching this extension (default: all
                        files)

For example:

python S3Uploader.py \
--bucket semantic.blogmatrix.com \
--access-key 0ZB0XFMV5NE1KM15DKR2 \
--extension gif,jpg,png,css,js \
--directory v10/media \
--root ~/htdocs

Finally, it's a matter of plugging in the changed files. Adrian does it like this:

Finally, it was just a matter of changing my chicagocrime.org templates to point to S3's URLs rather than my own URLs. That was a snap, thanks to Django's template inheritance and includes.

We do it with Apache rules:

RewriteRule ^/:root/(silk_icons/.*.png)$        http://s3.amazonaws.com/semantic.blogmatrix.com/$1  [R,L]
RewriteRule ^/:root/(v10/media/.*)$             http://s3.amazonaws.com/semantic.blogmatrix.com/$1  [R,L]
RewriteRule ^/:root/((MochiKit|tinymce|yui)/.*)$                http://s3.amazonaws.com/semantic.blogmatrix.com/$1  [R,L]

 

You're seeing the result here. All the background graphics and external javscript libraries are coming from Amazon S3.

Attached Documents:

Apache's mod_deflate

edit David P. Janes 2006-07-13 12:21 UTC add comment  ·  ·  ·

We've enabled mod_deflate on our Apache2 installation. This means that we'll only be sending about 10-20% of the data over the wire for our big fat HTML, JS and CSS files as the data will be GZIP compressed.

If you're considering using Apache2, you must explicitly enable it while building, i.e.:

./configure --enable-mods-shared=most --enable-deflate

Right now, this is what I've added to our config file:

LoadModule deflate_module modules/mod_deflate.so
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-javascript text/css

There's probably more mods coming to this yet though.