[uWSGI] on-demand multi-app setup

chuck odonnell chuck at odonnellpdc.com
Mon Apr 6 22:42:18 CEST 2015


On Mon, Apr 06, 2015 at 06:28:42PM +0200, Roberto De Ioris wrote:
> 
> > Hello.
> >
> > Hosting 200-300 WSGI apps. At any given time only 5-10 are active. The
> > goal is to have app load on demand, then die-on-idle. Active apps may
> > see a few hits a day, or a million hits a day. Others may sit for a
> > month with no traffic at all. Some apps use a unique virtualenv, so I
> > do not want them embedded in the same process. I would like each app
> > to be a process.
> >
> > Basically we want to duplicate an on-demand FastCGI setup, but remove
> > fastcgi from the equation.
> >
> > So far had luck implementing under nginx using:
> >
> >   [uwsgi]
> >   emperor = /usr/local/etc/uwsgi/sites
> >   emperor-on-demand-directory = /var/run/uwsgi
> >
> > And for each file in /usr/local/etc/uwsgi/sites
> >
> >   [uwsgi]
> >   callable = app
> >   mount = /run/p1=proj.py
> >   chdir = /sites/p1
> >   manage-script-name = true
> >   workers = 20
> >   cheaper-initial = 1
> >   cheaper-step = 1
> >   idle = 10
> >   cheaper = 0
> >   die-on-idle = true
> >   fastcgi-socket = /var/run/uwsgi/p1.socket
> >
> > However, I need this to work with Apache, but Apache/mod_proxy_uwsgi
> > does support dynamic Unix sockets.
> >
> > So the question is, is there another approach I can take using
> > something like an emperor with a fastrouter that starts an app upon
> > regex match, and then lets the app die-on-idle after a time?
> >
> > If I can do that, then I can configure Apache to route matching
> > requests to this single uWSGI process.
> >
> > Suggestions welcome.
> >
> >  Freebsd 10.1 Apache 2.4.12 uwsgi-2.0.10
> >
> 
> 
> What about fastrouter patterns ?
> 
> http://uwsgi-docs.readthedocs.org/en/latest/Fastrouter.html#way-2-fastrouter-use-pattern
> 
> You leave the setup as-is, and simply introduce apache + fastrouter
> instead of nginx only
> 

Okay, interesting, thank you.

So, are you saying:

  fastrouter-use-pattern /tmp/sockets/%s.sock

And set "UWSGI_FASTROUTER_KEY" within Apache on a per-request basis,
perhaps with mod_rewrite or some such?

Best,

Chuck



More information about the uWSGI mailing list