Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js vs Python [closed]

I'm rewriting my server and deciding between using Node.js and Python.

I prefer Javascript (as I'm extremely well versed in it) but this article is giving me pause. I'm curious if anyone has had any problems but also, I'm curious if there are any platform related virtues to one over the other.

Specifically, do either of them not-support/limit/excel-at

  • mySQL calls
  • imageMajik interaction
  • calls out to the system for file-system manipulation
  • calls to the web via WGET/Curl anything else
  • you can think of that normal CGI processes have to deal with.

I don't want to start an argument about the virtues of PHP or .Net, I have made a definitive decision to move to either Python or Node.js and was totally settled on Node.js, until I read the above article, so, really, I'm just looking for specific problems/virtues that people have had with these two tools.

Thanks in advance.

like image 682
Yevgeny Simkin Avatar asked Dec 20 '11 21:12

Yevgeny Simkin


1 Answers

There are two issues here:

  1. The choice of language. You'll need to decide for yourself if you prefer python or javascript, and which one offers the libraries you want. I can't help you with that part of the decision.
  2. The choice of IO model.

Unlike what the article suggests a single threaded non blocking IO model isn't bad in principle. Personally I like this model a lot, since it removes the complexities of multi-threading, while still working on a shared memory model.

Another advantage of this model is that because you don't need a thread per request, you can have many concurrent open requests.

One disadvantage is that without language support, you need to explicitly queue continuations, instead of writing the code in a simple imperative manner. C#5 attacks this problem with its async-await feature, and I wouldn't be surprised if node.js offered something similar in the future.

The article mainly talks about the second disadvantage: If you block the main thread, you block the whole server.

One of his examples is simply abuse: He implements a busy wait, instead of subscribing to an event. With correct programming this simply shouldn't happen.

The other example has more of a point: If you have CPU intensive calculations, you better not do them on the main thread. The simple solution to this is spinning of a worker thread, that does the calculation without touching memory used by the main thread. And once it's done it calls a callback on the main thread. Not sure if node.js offers this though. But since many server applications aren't CPU bound, this often isn't a problem at all.

In general that article is very low quality, and tells more about the author than about node.js. You shouldn't let it influence your decision.

like image 108
CodesInChaos Avatar answered Nov 15 '22 21:11

CodesInChaos