The uWSGI fastrouter is a c based, async uwsgi router you can use as a
ultra-fast routing solutions for multiple uWSGI instances running on the
same hot on external servers.
It is compiled in by default and (for now) can be configured only using
the uWSGI caching subsystem (every domain/hostname takes a cache entry).
Lets start it with a cache of 100 items running on port 3031 and 3032
(the first one is the port you will connect your webserver to, the second
is used by the instances to communicate their address)
uwsgi --fastrouter :3031 --fastrouter-use-cache --cache 100 --socket :3032
(simple command line, you can obviously add the master and so on, but
start with it for tests)
Now point your webserver to the address :3031 (as a normal uWSGI instance).
>From now on every request will search for hostname in the cache and will
forward request to the corresponding address.
Now let's write a simple wsgi app
import uwsgi
# delete old value from remote cache
uwsgi.cache_del('example.com', '127.0.0.1:3032')
# add the new mapping to the fastrouter remote cache
uwsgi.cache_set('example.com', uwsgi.opt['socket'], 0, '127.0.0.1:3032')
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return "Hello World"
Run it as always
uwsgi -s /tmp/mysock.sock --chmod=666 -w myapp
On startup the app will write in the fastrouter cache its domain/address
Some note:
The last arg of the uwsgi.cache_* api functions is the optional remote
server from where to send/get data (if not specified the local cache, if
available, will be used)
The uwsgi.opt['socket'] is a 0.9.7 extension of the api the contains all
the option you passed to the instance. In case of multiple sockets you can
get the first one as uwsgi.opt['socket'][0] and so on.
Using UNIX socket will force the fastrouter to use fd passing, so i
suggest you to use them to get a huge boost.
In the next 0.9.6 release (i will release it during the week end) i will
add support for fd passing, so users can start using the fastrouter with
stable instances.
Now join the fastrouter with the emperor, and welcome fast/automated
deploys :)
--
Roberto De Ioris
http://unbit.it
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi