A
A
Alexander Wolf2016-03-23 18:13:52
JavaScript
Alexander Wolf, 2016-03-23 18:13:52

How to limit cpu usage for a function?

Good afternoon! We have a function that runs on all users and rewrites some parameters. The function is not critical and its execution time is not important. However, since a simple loop is used, everything is executed in turn, thus loading the processor at 100% and very slowing down the main application.
You can, of course, stick a timeout, but I would like to do it more elegantly and simply set some kind of priority for the execution of this function. Using nodejs under meteor.
Does anyone have any thoughts on this?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
ILE, 2016-03-24
@mannaro

If you want to do it in NodeJS. At the moment, the maximum that you will do:
1) Run NodeJS in multi-threaded mode
2) You will use timers
3) 1 + 2

I
Ilya Erokhin, 2016-03-24
@AirWorker

> users in one place, but there are still a bunch of tables, the data from which must be collected together and recorded in the user field.
Don't dig there. This needs to be resolved inside the database - for example, Postgres, stored procedures.
To drive data back and forth between the database and the application is empty. The database must be responsible for the integrity of the data.

S
sim3x, 2016-03-23
@sim3x

man nice

nice ./script.js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question