How to increase meteor.call timeout


#1

Helle everybody, i built an accounting app that takes in an xls file filled with stock operations and does the accounting(generating balance,journals…) on the server. the fact is i have a meteor method that is called from the client and that does the accounting.Now within this method there’s a lot of loops and filters,maps and array operations going on, such that when the file is too operations loaded the works takes time.As the method is running on the server and takes a bit more than 1 min to complete(since it’s synchronous) the websocket gets disconnected for timeoutmbut i still can see the results on the server log showing that even tough it took some time to complete it still completed awesomely.

How can i increase sockjs timeout value so that at least im sure my tasks frun flawlessly?

I thought of moving the method on the client but i dont think it is a good solution.Even after optimizing the method just when the timeout occurs i get the result on the server just seconds away.

Please guys help me…Sorry for the english i hope i made myself understandable


#2

I would recommend reconsidering the entire design. Personally, I would create a new document in the DB and then put the result into that new document. Meanwhile, on client, you would proceed to a new page where it would show a processing message until the results would be populated in the DB.

To begin though you might want to look into unblock, which I think might help you here.


#3

thanks for the quick reply,

i did use this.unblock() and even the fibers/future approach to no avail…i guess i have to change the entire design if it comes to that


#4

I would put the processing into its own function that runs independently. Try to separate things out a bit. This will also allow you to optimize things down the line. For example, if you have many people uploading stuff to be analyzed then you might want to get the initial info out in one function and then run the analytics in another. Since these analytics will be computation heavy you might want to limit how many you do and create a queue. The results will then be saved in the DB, you can then subscribe to it and hence display the results when they are available.
Just how I would approach it from what you have told me. Also take a look at Meteor.apply, it has a bit more options to configure, though I’m not sure how much they will be of help.


#5

If you are doing intensive processing like this which blocks the event loop, I would recommend, if possible, offloading it to a separate server.


#6

unblock will not help in this situation - it does not magically make the server process any quicker, nor does it indicate to the client that it should wait any longer. For more on unblock, check out this article.

The best approach is @copleykj’s: use the method to kick off an asynchronous server process (maybe a service worker) and send an immediate response to the client to satisfy the timeout requirement. Let the service worker update the database when it’s finished and livedata will take care of updating the client reactively.


#7

Ok and how do i implement a service worker in meteor?


#8

It doesn’t have to be a service-worker - it could be a separate Meteor microservice.

You could take a look at the differential:workers package. Note the examples in there are in CoffeeScript - you’ll need to translate those into JavaScript. For example,

Job.push new LoadRetentionJob
  projectId: projectId
  cohortInterval: "day"

translates to:

Job.push(new LoadRetentionJob({
  projectId,
  cohortInterval: 'day'
}));

#9

Thanks a lot ill look into these solutions and update my code…well i know it is by design but we should have some kind of mean to increase socksjs delay just for debug purposes.Anyways Thank you a lot ill go the async way