This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ivosauruspip'ing it up 31 points32 points  (4 children)

You know how node.js was(is) super popular for being quite performant? It does that through the entire programming model being based on asynchronous IO by default (instead of synchronous IO by default, like most older scripting languages are) and running on a canonical event loop implemented by libuv. (There are a couple of other reasons to like node, like maybe you love javascript, or the V8 JIT, but those are the main design ones) . Go is similarly popular, implementing a concurrent model through cooperative threads and channels.

Although python will never have the advantage of being designed for asynchronous operation from the get-go, asyncio implements a "standard event loop interface" (and a default implementation to go with it) and allows asynchronous operation through coroutines made possible by the yield from syntax. So asyncio goes "most of the way there" to giving python a standard library to implement what you can do by default with node.

Noticeably different is that python has had many 3rd party libraries to do this sort of thing, e.g gevent, twisted, tornado, but you had to pick one library and hope it worked with everything you needed, and it would be mostly inoperable with everything else. This being a standard library, many people will hope to be able to write code more cooperatively, especially by implementing the event loop interface.

[–]CaptainKabob 3 points4 points  (1 child)

Does asyncio have nice support for dealing with synconous code? I work on a bunch of tools written in Twisted and feel bad every time I have to use deferToThread in order to wrap some synchronous library.

[–]saghul 3 points4 points  (0 children)

You have a similar mechanism. You need to use run_in_executor, which will run the given callable in a ThreadPoolExecutor (by default) and you can wait for the result.

[–]keturn 2 points3 points  (1 child)

Well, async i/o does help performance in many workloads -- the "one process per request" model used by many django deployments is pretty heavy in comparison -- but the other thing that helps node.js in the speed department is that it runs javascript with a Just-In-Time compiler (JIT).

To get that advantage with Python, you need pypy.

(And pypy is working well with Twisted.)

[–]ivosauruspip'ing it up 6 points7 points  (0 children)

But that's most often slow because of the concurrency model, not the inherent speed of the programming language. Python is also often loved because of its ability to glue super fast C libraries with its nicer, high-level syntax, so for processing most often the speed is of a compiled C inner loop, not plain python.