user2867106
user2867106

Reputation: 1131

node js on heroku - request timeout issue

I am using Sails js (node js framework) and running it on Heroku and locally.

The API function reads from an external file and performs long computations that might take hours on the queries it read.

My concern is that after a few minutes it returns with timeout.

I have 2 questions:

Upvotes: 0

Views: 2344

Answers (1)

hunterloftis
hunterloftis

Reputation: 13799

You should use the worker pattern to accomplish any work that would take more than a second or so:

"Web servers should focus on serving users as quickly as possible. Any non-trivial work that could slow down your user’s experience should be done asynchronously outside of the web process."

"The Flow

  1. Web and worker processes connect to the same message queue.
  2. A process adds a job to the queue and gets a url.
  3. A worker process receives and starts the job from the queue.
  4. The client can poll the provided url for updates.
  5. On completion, the worker stores results in a database."

Upvotes: 1

Related Questions