Umren
Umren

Reputation: 392

Any advantage of using node.js for task queue worker instead of other languages?

Will i have any advantage of using Node.js for task queue worker instead of any other language, like PHP/Python/Ruby?

I want to learn Redis for simple task queue tasks like sending big ammounts of email and do not want keeping users to wait for establishing connection etc.

So the questions is: does async nature of node.js help in this scenario or is it useless?

P.S. i know that node is faster than any of this language in memory consumption and computation because of effecient V8 engine, maybe it's possible to win on this field?

Upvotes: 2

Views: 1352

Answers (2)

ngourley
ngourley

Reputation: 243

I have used Node.js for task worker for jobs that call runnable webpages written in PHP or running commands on certain hosts. In both these instances Node is just initializing (triggering) the job, waiting for and then evaluating the result. The heavy lifting / CPU intensive work is done by another system / program.

Hope this helps!

Upvotes: 0

tadman
tadman

Reputation: 211580

It really depends what you're familiar with, and which language provides the support for the work you're trying to perform. For example, if you're rendering PDF files, of the languages you're comfortable with, which has the best PDF library?

Workers have the advantage of being able to run synchronous, blocking code because of the way work is fanned out to multiple workers. Having asynchronous workers simply means each worker process can, theoretically, do more work than a single-threaded blocking equivalent.

In languages that have threading support, though, this advantage is slim. Python and Ruby both support threading which is a way of running multiple blocks of synchronous code in parallel.

When building a distributed worker queue for a high volume email application, I implemented most of it in asynchronous non-blocking Ruby with the EventMachine library. Redis is used as a backing store to ensure idempotency.

Writing proper asynchronous, event-driven code has been challenging since you need to ensure all your libraries are non-blocking or you could cause the worker process to jam. This is not unlike finding libraries that are thread-safe when doing threading.

Node can do a lot of things quite well, but threading is not one of them. The good news is that most Node libraries are non-blocking by default so compatibility is less of a concern. The same cannot be said for most Python and Ruby libraries, but the majority of these are at least thread-safe.

In the end it depends what you're most comfortable with. A distributed worker system can have several different languages involved, so you won't necessarily be locked in to any particular one.

Upvotes: 1

Related Questions