Reddit Web Server

December 11, 2009 § Leave a comment

As of late November 2009 – December 2009, It appears that Reddit is using Tornado web server. Interesting.

You can get the same type of information by using curl (curl -I http://www.reddit.com)

Source:

6diagrams.com: Create your own forum.

October 4, 2009 § Leave a comment

I’ve been building this little thing for a while now. That little thing is Forum software.

It does everything you would expect from using PHPBB, Reddit or HackerNews, and more. With 6diagrams you can bookmark that interesting topic without having to go through your piles of links in that bookmark tab. It also, of course, remember your own posting.

To learn more of what it can do, please follow this link.

Why?

Already 3 guys asked me this questions. Why are you building this thing that looks like Reddit or HackerNews rip off? Well… in my defense, Reddit, HackerNews, (and Google) do a great job in displaying list of interesting things effectively. It’s not a coincidence that I’m following the path of Reddit/HackerNews because I want to follow the path of success.

Besides that UX decision, I build this because I’m starting to have difficulties when blogging. The standards of blogging is going higher and higher. Blogging takes more than just well-written article these days. I have to stay consistent in following the blogs general theme. If I want to write slightly controversial topic, I better do a lot of research and write it in concise manner. When my post is mildly interesting, I have to be vigilant in responding to visitors in less than 24 hours time frame. It’s tough (I believe this is 1 of many keys to Twitter success, it’s very personal).

Those are too much burden for a programmer who have probably only 1 hour a week to write a blog post. Sometimes I just want to voice out my opinion regardless of the accuracy (I never policed any of my real life friends when it comes to factual accuracy, I’m hoping to experience the same thing online). I want to write something that’s interesting enough to create a conversation for social interaction and personal knowledge.

That’s why I defaulted back to Forum format. Forum is great, it doesn’t force people to use real name. Participation in a thread can extends to weeks, so that I have time to respond to conversation (just like mailing list).

Most forums have informal, laid-back conversation about common things that people like, such as OSS project, anime, coffee grinders, Mitsubishi Evolution, etc. There’s no pressure to be right, everyone is simply sharing and hanging out.

That’s why I build 6diagrams.

Technical

6diagrams is open source forum software. The project page can be found here. It is built using Python, Pylons, MySQL, TinyMCE, and Tokyo Tyrant.

For those who stopped by and created accounts, I hope you find 6diagrams enjoyable.

Pylons: production environments

September 20, 2009 § Leave a comment

First of all, there are several wiki posts at pylonshq.com already, below are some of them:

I believe there’s not a single best solution in choosing any of these strategies. This post is intended as sharing my experience in some of these. I’m definitely not set on particular one and will change my mind once I gained better understanding.

My testing methodology

I’m currently testing multiple deployment configurations on the same app, thus giving me the opportunity to blog about it. I use Apache Benchmark (on client side), top and ps afx on server side. My machine is 1 Linode 1440 instance.

My AB setup are:

ab -n 500 -c 50 -k http://rootapp.com/

ab -n 1200 -c 50 -k http://rootapp.com/

ab -n 1500 -c 50 -k http://rootapp.com/

ab -n 800 -c 800 -k http://rootapp.com/

The results varied insignificantly with some subtle interesting differences. I’ll explain those below.

Note: I am testing these configuration on dynamic AJAX-y web application, thus reporting hard numbers is not very useful.

CherryPy vs Paste HTTP Server behind NGINX

One thingĀ  that I noticed immediately is that CherryPy has better performance than Paste’s HTTP server. On both, having multiple processes does not help much on overall performance, but significantly reduces number of failed requests. When run under multiple processes, CherryPy consistently have the least number of failed requests.

For my setup having 7-8 processes is the sweet spot. When I have more than that, top is telling me that the latter processes are under utilized.

Setting up CherryPy on your production.ini is painless:

use = egg:PasteScript#cherrypy
numthreads = 20
request_queue_size = 512
host = %(http_host)s
port = %(http_port)s

By just comparing the two, CherryPy is easily the winner.

Lighttpd and SCGI

This gist is basic configuration to get SCGI up and running on lighttpd while the following is setup for your production.ini:

use = egg:Flup#scgi_thread
host = %(http_host)s
port = %(http_port)s

given the same AB configuration as CherryPy and Paste counterpart, lighttpd and SCGI consistently capable of handling 30 requests/seconds. About 8-10 requests/seconds more than CherryPy. Even though this setup is better, I noticed that memory consumption continues to go up after 2 weeks. I haven’t spend much time in investigating why. The reason I didn’t choose this path is more because I simply like NGINX better.

If only SCGI module on NGINX isn’t so experimental.

NGINX and FastCGI

This gist is basic configuration to get FastCGI running on NGINX while the following is setup for your production.ini:

use = egg:Flup#fcgi_thread
host = %(http_host)s
port = %(http_port)s

With this configuration, I consistently get about 25 requests/seconds. It’s a bit behind lighttpd and SCGI configuration. Interestingly, when run under ab -n 1500 -c 50 -k, this configuration hangs NGINX requiring it to be restarted. It only happen once though.

Again, when load balanced properly (depending on your app), any one of these configurations would work well. Hopefully this post can help others to get up to speed in Pylons deployment.

Pylons: Tokyo and Redis for caching backend

August 25, 2009 § Leave a comment

First of all, I love Tokyo and already use Tokyo as secondary database for Pylons development and so far it has been a great success.

Since my box does not have a lot of memory, and a lot more disk space, it make sense to use Tokyo as caching solution instead of memcache.

Quick googling revealed that Jack Hsu has already implemented beaker’s Tokyo extension. His snippet works out of the box.

For my use case, I change the serializing strategy to using pickle instead of json. My reasoning is that pickle allows serializing complex object and I don’t have requirement for portability on cache data.

You can find the Tokyo extension here. I added Redis extension as well since it is very similar to Tokyo.

Edit (08/26/2009): Added extension for Dynomite

Edit (08/26/2009): Added extension for Ringo

[fixing bad layout]

Pylons: Session set for all subdomains

July 14, 2009 § Leave a comment

In order to have Beaker’s session applied to all subdomains, set cookie_domain to: .yourdomain.com (notice the dot in front).

In pylons, the cookie domain is available as: beaker.session.cookie_domain.

Also, in Google Group, Cezary mentioned to set also set sub_domain in routing.py

Note:

  • This howto won’t work in Firefox. As far as I know, only Safari allows me to do this.

Reference:

Pylons: Testing Configuration

June 7, 2009 § Leave a comment

It’s nice that Pylons include nosetest and TestUnit as part of its testing framework.

Unfortunately, using those for unit testing inside Pylons is not trivial, not obvious, and inconvenient.

For examples:

  • I can only run nosetests on top-level directory because config is expecting ‘test.ini’ file. That’s inconvenient.
  • It is not obvious how build sqlalchemy’s engine inside tests/__init__.py. Ideally, I can build the engine based on test.ini configurations.

To answer those questions, this is how my __init__.py looks like:

The __init__ file solves various problems:

  • I can run nosetests anywhere inside project’s directory tree.
  • With simple convention, __init__ will look for test.ini file on top-level directory.
  • SqlAlchemy engine is built using configuration set in test.ini

I hope this snippet can help readers in getting up to speed in Pylons even quicker.

Yes! Syntax Highlighting for Mako in TextMate!

May 31, 2009 § 1 Comment

For the longest time I kept staring at ‘plain text mode’ while editing Mako templates. No Mas!

TextMate bundle for Mako template has existed.

To install:

  • cd ~/Library/Application\ Support/TextMate/Bundles/
  • svn co http://svn.makotemplates.org/contrib/textmate/Mako.tmbundle

After Reloading your bundle, syntax highlighting is available under HTML (Mako).

Reference:


									

Pylons Quickie: Mako Output

May 24, 2009 § Leave a comment

By default Mako HTML escapes all output.

To NOT have this behavior, change the setting of TemplateLookup in environment.py.

Resources:

Pylons Quickie: I want to use distance_of_time_in_words

May 17, 2009 § Leave a comment

distance_of_time_in_words is a useful function that converts boring looking datetime into something more attractive (and SEO optimized) like: 30 seconds ago.

Pylons gain this functionality via WebHelper which blatantly inspired by Rails.

But, out of the box, this functionality does not exists in my templates. To enable it, I need to add this line in helpers.py:

from webhelpers.date import distance_of_time_in_words

Resource:

WebHelpers Documentation

Pylons Cheat Sheet

May 13, 2009 § Leave a comment

http://workaround.org/pylons/pylons-cheatsheet.html

Where Am I?

You are currently browsing entries tagged with pylons at RAPD.