Bite by MemoryError

Gentoo February 27th, 2008

In the last post, I worked through the installation and deployment for Django application. And I setup a MoinMoin Wiki as well. Everything works fine until I switched back and forth between the blog and wiki, I got a MemoryError like this:

Mod_python error: “PythonHandler django.core.handlers.modpython”
Traceback (most recent call last):

File “/usr/lib/python2.5/mod_python/apache.py”, line 299, in HandlerDispatch
result = object(req)

File “/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py”, line 188, in handler
return ModPythonHandler()(req)

MemoryError

It is most likely that the two application’s memory footprints exceed the limit. Yes, FastCGI would rescue; unfortunately, it is another advanced feature you have to pay for. There is no explicitly regulation when I signed up but I think it is quite reasonable to set the resource quota as virtual server is essentially shared hosting shared anyway. I would contact the custom service of Jumpline tomorrow for a better understanding.

Update: just contact the customer service of Jumpline, they seen have no QoS of the memory footprint or CPU load. I really have no idea whether this good news or bad news.

HOWTO deploy Django in Jumpline

Web February 24th, 2008

The blogosphere discussed the headache of deployment for modern Web Framework on shared hosting recently in couple weeks ago. This HOWTO documents the bumps and workaround in deploying Django to Jumpline‘s VDS(Virtual Dedicated Servers) hosting.

Compared with the ironclad shared hosting, VDS provides SSH access, and private Apache server. Jumpline’s plan is also shipped with mod_python(python 2.5) and write access to PYTHON/site-package and /usr/local/bin, that make the whole process less painful.

Setup the VirtualHost

Add a sub-domain as planet.kunxi.org in VDS console as our testbed.

Install Django SVN

It is a pity that Subversion is not installed in the chroot jail. In fact the Subversion hosting is a premium feature you need to pay for. Anyway, we can just check out the code in the local machine, then copy it back to the server. In the server:

python setup.py build
python setup.py install –prefix=/home/lib

If you happen not to have write privilege PYTHON/site-package, you may consider add –prefix to override the default installation path, then add the prefix to your PYTHONPATH environment variable.

Setup the mod_python

Load mod_python in httpd.conf

LoadModule python_module modules/mod_python.so

As the name suggests, planet.kunxi.org is a feed aggregation portal based upon FeedJack, some enhancement are in plan to scratch the etch, now it is just mere a simple deployment:

<VirtualHost *:80>
    ServerName planet.kunxi.org
    DocumentRoot /var/www/planet
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    PythonDebug On
    PythonPath "['/home/projects'] + sys.path"
    SetEnv DJANGO_SETTINGS_MODULE feedpipe.settings
    <Location "/media">
        SetHandler None
    </Location>
    <Location "/static">
        SetHandler None
    </Location>
</VirtualHost>

/media and /static are set to host static media contents. /media is mere a soft symbol link to django/contrib/admin/media. We also link /static/feedjack to feedjack’s media files as FeedJack’s document suggests. Here is the feedpipe.settings:

MEDIA_ROOT = ‘/var/www/planet/static’
MEDIA_URL = ‘/static/’
ADMIN_MEDIA_PREFIX = ‘/media/’

Restart httpd, done.

Put another two eggs in the basket

Development February 18th, 2008

If you are a loyal reader of programming.reddit.com, you may consider Java is dying dead, and only very few developers are using .NET, most programmers in the world either use Haskell or ErLang, some die-hard old school may stick to their list, scheme. Period.

I am one of the readers. Programming Haskell demonstrates the beauty of the function language, and Glasgow Haskell Compiler (GHC) from Microsoft Research is able to generate native machine code to compete with native C program!

Erlang on the other hand is a dynamic language, so it pay off this flexibility by performance. I think this thread in Erlang mailing list is the best head to head of Haskell vs Erlang. Here is my summary:

  • Haskell runs fast due to its native code compiler with full static typing
  • Haskell’s laziness make it difficult to estimate the preformance
  • Erlang is reliable(proved by Ericsson) and shines on con-currency programming, for example Apache vs. Yaws

But language is not only factor that matters the success, the platform and library are. That is the reason most companies build their applications on Java or .NET as the ecosystem would not allow the two platforms fail. But quite a few start-up companies prefer PHP, Python or Ruby for their agility(is PHP an exception?) before the scalability point is hit.

As personal interest, I would rather put both two eggs in my basket, just for fun.

ID3 tag for programmers

Desktop February 7th, 2008

If you feel unease to do anything in a command line, or you have no idea about what regular expression is, please stop; I am quite sure this recipe is just not your cup of tea.

eyeD3util is a small, yet powerful IMHO, package that handles nasty ID3 tags that GUI may not offer. As the name suggests, it is based upon eyeD3, thanks to Travis’ great work. There are three apps targeting different etches:

eyeD3conv.py
eyeD3conv.py convert the ill-encoded tag, and convert them to Unicode. Check this for a full story. Though never tested other than Chinese GB2312, theoretically, it can handle the tag encoded in non-latin1 locale. Please leave a comment if you have a success story.

eyeD3ffn.py
What if no tag attached like Hanes? Well, if we could get the essential information, the track number and name, we may add other meta data using eyeD3. This script parses the filename via the regular expression to get all available meta data you need, for example:

eyeD3ffn.py "(?P<n>.*) – (?P<t>.*)\.mp3" "02 – 祝我幸福.mp3"
Apply ID3 v2.3 tag to 02 – 祝我幸福.mp3
setTrackNum:  [’02′, None]
setTitle:  祝我幸福

eyeD3validate.py
To be a perfectionist, I would rather check whether the MP3 file includes all essential information required: title, artist, album, track number, year of publish and genre. This script just did the minimum, nothing less, nothing more.

Comments? Feedbacks?

New look for the New Year

Web February 4th, 2008

Happy New Year! The traditional Chinese new year aka the Spring Festival is coming. And I decided to change the look of this blog, *finally*, after two years.

The new theme is based upon ericulous‘ GenkiTheme. I really love the built-in color scheme which is the last thing I would do it from the scratch. And the three-column layout is such a different experience for me as well.

The following plugins are used for the navigation and SEO:

  • Customizable Post Listings
  • Sitemap Tags
  • WP 2.3 Related Posts
  • Top Posts By Category

Since WordPress 2.3 supports tag out of the box, the Simple Tag plugin is not longer needed,
WP 2.3 Related Posts uses the tag for relation between posts, that is much more lightweight than the full-text search alternative.

Top Posts By Category is used for the Popular Post since Popular Contest does not work very well with WP-Cache. Customizable Post Listings is just for Random Post.

There are also some minor modification tailed for my personal preference as well:

  • The color of the blog title is OK in Firefox on Linux, but too flashy either in MSIE or Firefox on Windows.
  • The HTML tag for post title is h2. h1 may make more sense for the bot.
  • The same applies to the blog title in the sidebar

There are still more things to go:

  • Embrace OpenID/Live ID and other 3rd party authentication to encourage comments
  • Add avatar support