Python pulsar with uWSGI

101 views
Skip to first unread message

Pas

unread,
Sep 30, 2014, 8:02:52 AM9/30/14
to lsbardel, python...@googlegroups.com
Hello!

I hope it's okay to hijack this thread, as with regards to asyncio, I'd like to ask about uWSGI support (it has asyncio [tulip?] support http://uwsgi-docs.readthedocs.org/en/latest/asyncio.html and support for various other async event loops http://uwsgi-docs.readthedocs.org/en/latest/Async.html ). Or maybe uWSGI is unnecessary, pulsar's implementation is performant and capable enough?

Also, would you recommend putting anything in front of pulsar for "production" deployments? (nginx? or they muck up latency because of potentially buffering the incoming requests?)

Thanks,
Pas


On Sun, Sep 28, 2014 at 10:08 AM, lsbardel <luca.sb...@gmail.com> wrote:
Hi,

On Saturday, September 27, 2014 11:19:50 PM UTC+1, vana...@ucar.edu wrote:
I’m very new to python-pulsar, so please bear with me.

I'm trying to use the Twisted compatibility mode of pulsar, since this

is the only way I know of to get a XML-RPC server running under
asyncio.

To write a XML-RPC server for asyncio shouldn't be too difficult when using pulsar.
Pulsar has a JSON-RPC wsgi middleware which is not dissimilar.

All you need is a XMLRPC class inheriting from RpcHandler and implement the callable method.

from pulsar.apps.rpc import RpcHandler

class XMLRPC(RpcHandler):

   
def __call__(self, request):
       
...
 
I'm happy to help you out if you decide to go for this solution.
Once you have the XMLRPC handler you can write your application like

from pulsar.apps import wsgi

class 
MyRpc(XMLRPC):
    
    
def rpc_add(self, request, a, b):
        
return a+b


class Wsgi(wsgi.LazyWsgi):

    def handler(self, environ=None):
        app = wsgi.Router('/', post=MyRpc())
        return wsgi.wsgiHandler([app])


if __name__ == '__main__':
    wsgi.WsgiServer(Wsgi()).start()

If you want to re-use twisted implementation you can try with pulsar.apps.tx as you mentioned but I'm not sure it will work.


If I comment out the following lines:
from pulsar.apps.tx import tx


This is a crucial import. It replaces the the twisted reactor with a proxy to the asyncio event loop.
If you don't use it you are not using asyncio but twisted instead.
 

from pulsar.utils.log import process_global

You don't need this import 
 


and add a reactor.run() call to main(), the script runs my XML-RPC
server, with repeated calls to 'doPoll()', as I expect.

reactor.run is switched off by pulsar when importing tx.
To run the event loop you either use a pulsar application as above or asyncio directly

asyncio.get_eventloop().run_forever()



2) If have two different files in my application that both import pulsar.apps.tx, won’t this cause two calls to _reactor.run()?

Yes but reactor.run does nothing as previously mentioned. 

--
You received this message because you are subscribed to the Google Groups "python-pulsar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-pulsa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

lsbardel

unread,
Oct 1, 2014, 2:47:00 AM10/1/14
to python...@googlegroups.com, luca.sb...@gmail.com
On Tuesday, September 30, 2014 1:02:52 PM UTC+1, Pas wrote:
Hello!

I hope it's okay to hijack this thread, as with regards to asyncio, I'd like to ask about uWSGI support (it has asyncio [tulip?] support http://uwsgi-docs.readthedocs.org/en/latest/asyncio.html and support for various other async event loops http://uwsgi-docs.readthedocs.org/en/latest/Async.html ). Or maybe uWSGI is unnecessary, pulsar's implementation is performant and capable enough?
 
If uWsgi works with asyncio than it should work with pulsar.
Pulsar has its own wsgi server, therefore compatibility has never been tested. Pulsar should be performant, especially in multiprocessing mode, but needs more people to use it in heavy traffic applications.


Also, would you recommend putting anything in front of pulsar for "production" deployments? (nginx? or they muck up latency because of potentially buffering the incoming requests?)

You could put nginx in front of pulsar, it depends on what sort of media you are serving.
If there are a lot of static files, nginx is a good solution.

Reply all
Reply to author
Forward
0 new messages