'Using the same class instance for database operation over every different request
On my NodeJS/Express backend implementation, each incoming request will instanciate a new class Controller, with a handler method for this specific route only.
This mean that every incoming request, will allocate some memory to instanciate the class that will handle the response, and then free this memory.
In order to manipulate the database, the new instanciate controller will use other models class, which are not instanciate at each request, but when the server start.
This mean that every models (one for each table), is kinda global and used by every new controller instance.
Those models those not have state, and they are more likely some kind of functions library.
Knowing this, I am still wondering if there is any kind of side effect possible if many request arrive simultaneously ? Even if those models doesnt have any state that ( like this.data = 1 ) that would be cross used between 2 request, I am not totally sure
Also I decided this implementation because I do think that instanciate new models for each request may start to consume too much memory in case of several request simultaneous, especially because there is also other class which are services and helpers that follow the same logic, but maybe I am wrong
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
