Philip Thrasher
Web hacker at a private cyber security company.
| class StaticFileHandler(RequestHandler): | |
| """A simple handler that can serve static content from a directory. | |
| To map a path to this handler for a static data directory /var/www, | |
| you would add a line to your application like: | |
| application = web.Application([ | |
| (r"/static/(.*)", web.StaticFileHandler, {"path": "/var/www"}), | |
| ]) |
| """ | |
| This is a simple example of WebSocket + Tornado + Redis Pub/Sub usage. | |
| Do not forget to replace YOURSERVER by the correct value. | |
| Keep in mind that you need the *very latest* version of your web browser. | |
| You also need to add Jacob Kristhammar's websocket implementation to Tornado: | |
| Grab it here: | |
| http://gist.github.com/526746 | |
| Or clone my fork of Tornado with websocket included: | |
| http://github.com/pelletier/tornado | |
| Oh and the Pub/Sub protocol is only available in Redis 2.0.0: |
Wensheng Wang, 10/1/11
Source: http://blog.wensheng.org/2011/10/performance-of-flask-tornado-gevent-and.html
When choosing a web framework, I pretty much have eyes set on Tornado. But I heard good things about Flask and Gevent. So I tested the performance of each and combinations of the three. I chose something just a little more advanced than a "Hello World" program to write - one that use templates. Here are the codes:
| from kombu import Exchange | |
| from kombu import Queue | |
| from kombu import BrokerConnection | |
| class ProduceConsume(object): | |
| def __init__(self, exchange_name, **options): | |
| exchange = Exchange(exchange_name, type='fanout', durable=False) | |
| queue_name = options.get('queue', exchange_name+'_queue') | |
| self.queue = Queue(queue_name ,exchange) |
| import time | |
| import redis | |
| import urllib | |
| import threading | |
| import simplejson | |
| class Generator(threading.Thread): | |
| def __init__(self, generator, output_channel, _redis=None): | |
| threading.Thread.__init__(self) | |
| self.generator = generator |
| import redis | |
| import threading | |
| class Listener(threading.Thread): | |
| def __init__(self, r, channels): | |
| threading.Thread.__init__(self) | |
| self.redis = r | |
| self.pubsub = self.redis.pubsub() | |
| self.pubsub.subscribe(channels) | |
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| """ | |
| Hierarchical link clustering | |
| ============================ | |
| :Author: Tamás Nepusz | |
| This is an implementation of the hierarchical link clustering algorithm of Ahn | |
| et al. The results provided by this implementation match those of the original |
| from multiprocessing import Pool | |
| from functools import partial | |
| def _pickle_method(method): | |
| func_name = method.im_func.__name__ | |
| obj = method.im_self | |
| cls = method.im_class | |
| if func_name.startswith('__') and not func_name.endswith('__'): #deal with mangled names | |
| cls_name = cls.__name__.lstrip('_') | |
| func_name = '_' + cls_name + func_name |
| System | |
| ====== | |
| Windows 7 | |
| Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] | |
| Small data | |
| ========== |