eru-manifestation / erus-will

A project dedicated to SATM
0 stars 0 forks source link

Node.js performance on multiple concurrent clients #3

Open eru-manifestation opened 10 months ago

eru-manifestation commented 10 months ago
eru-manifestation commented 10 months ago

https://github.com/nodejs/node-addon-examples/blob/main/src/5-async-work/async_work_promise/node-addon-api/worker.h Write each method as a call to a worker class which would receive an enviroment and the type of action to perform. This would be managed by the working thread and returned as a promise. The promise is returned by the original method and handled in the javascript.

eru-manifestation commented 10 months ago

After some search, I have a deeper insight on the matter and understand the basics from Node.js event loop and worker loop management. The contents of this video clarifies that I need another thread of execution for the CPU-costly task of executing orders in the CLIPS environment. Even if I implemented these functions as async, promises or callbacks, they would queue into the event loop and completely paralize the server. In order to implement worker threads (the fittest choice for this project, in my opinion), I would need to implement this as a N-API or make it context aware (reason). The simplest choice seems to be taking this chance to implement my addon as an N-API addon and then create an AsyncWorker subclass to perform those costly tasks. I hope to be able to dodge memory leaks by implementing AddEnvironmentCleanupHook if needed.