7 ms·
We've just recently started using Sanic[0] paired with Redis to great effect for a very high throughput web service. It also uses Python 3 asyncio/uvloop at it
by erikcw 9y ago
We've just recently started using Sanic[0] paired with Redis to great effect for a very high throughput web service. It also uses Python 3 asyncio/uvloop at its core. So far very happy with it.
[0] https://github.com/channelcat/sanic https://github.com/channelcat/sanic
- sandGorgon 9y agoThere is also ApiStar - https://github.com/tomchristie/apistar https://github.com/tomchristie/apistar It's built by Tom Christie - the original author of Django Rest Foundation. http://discuss.apistar.org/t/how-does-api-star-fit-in-with-django-rest-framework/15 http://discuss.apistar.org/t/how-does-api-star-fit-in-with-d...
- theptip 9y agoInteresting, hadn't seen that yet; thanks for sharing. Does look like it'll have some nice design concepts -- I've definitely come to view Django/DRF's strong coupling to the ORM as a hinderance to architectural flexibility/sanity as my application has grown. Interestingly it eschews Swagger/OpenAPI in favour of JSON Schema, wonder how that'll pan out; I like the promise of codegen that swagger offers, but haven't found the generated clients to be particularly usable.
- tomchristie 9y agoOne thing to clarify here. Swagger/OpenAPI use JSON Schema in order to describe parameters and response structures. The rest of the schema work will start to fall into place pretty quickly now that we've got the groundwork done. Swagger generation based on the annotations will be one of the features, but there'll be plenty more to get excited about too.
- theptip 9y agoIsn't Swagger a subset of JSON Schema though? [1] If APIStar happens to target the same subset, that's not a problem of course. [1]: http://stackoverflow.com/a/32386131/37481 http://stackoverflow.com/a/32386131/37481
- zebra9978 9y agoany particular reason you are using BSD license ? With all due respect, this does not cover a patent grant like the Apache license and could be a poison pill for companies to adopt.
- tomchristie 9y agoI just had a quick scan over the licenses of other projects used for server side projects. Projects using BSD/MIT include Node, Go, Rails, Django, and Flask. I'm happy with the choice.
- sandGorgon 9y agoSorry to interject - but that's not completely true. Go comes with a separate patent disclaimer. https://golang.org/PATENTS https://golang.org/PATENTS And IMHO nodejs is not a standard BSD license and comes with patent grant. That discussion went on for a year in the TSC . https://github.com/nodejs/node/blob/master/LICENSE https://github.com/nodejs/node/blob/master/LICENSE In general, this stuff is not always evident. But the BSD license by itself is not as good as Apache. While in doubt, use Apache ! P.S. fyi, doing this later is super heavy-duty hard.
- wiremine 9y agoBeen doing the same thing: Sanic is great!
- Waterluvian 9y agoI have never found a good example of a Python web server that provides some mechanism for statefulness. Is it just fundamentally not possible to have shared state among requests handled by the threads of a process? Sanic's examples seem to be the same as Flask's: self-contained function calls attached to endpoints. I keep hitting a wall with Python when I want to do something like: 1. subscribe to a websocket connection and keep the last received message in state 2. expose an http endpoint to let a client GET that last message.
- quinnftw 9y agoYou can use caching to mimic this behaviour in Flask, I.e. http://flask.pocoo.org/docs/0.12/patterns/caching/ http://flask.pocoo.org/docs/0.12/patterns/caching/ I'm not sure how this works with multiple threads though, I imagine you would have to synchronize it yourself.
- tyingq 9y agoRedis's lpush, and rpop plus some naming scheme might suffice. Everything is atomic, so the thread bit is covered.
- deleted 9y ago[deleted]
- raziel2p 9y agoIs that really something you want to do in-memory? Once you have to start multiple worker processes or application servers behind a load balancer, you'll have to re-implement it with some sort of shared persistant store like Redis.
- icebraining 9y agoNot really, you can use a multiprocessing.Manager to share a plain old dict or list across multiple worker processes: https://docs.python.org/3/library/multiprocessing.html#sharing-state-between-processes https://docs.python.org/3/library/multiprocessing.html#shari...
- fafhrd91 9y agoproblem with Sanic that it does not implement streaming properly. so it is very easy to kill any Sanic process, 10-20 seconds. again any.
- dalanmiller 9y agoWould you mind elaborating?
- fafhrd91 9y agocheck Sanic code, it loads whole incoming payload into memory before processing it. event for 404, so I can write very simple script that would consume all memory. and you can not really protect sanic service with proxy (nginx)
- vram22 9y agoAny idea how Sanic compares with Falcon? I read somewhere recently that Falcon was quite fast. I tried out Hug, which is built on Falcon, but only for a small demo app, not done any benchmarking.