Log In    |    Knowledge Base    |    4D Home
Tech Tip: Avoid Heavy Simultaneous Procedures
Published On: July 20, 2023

Resource managment is an important factor when trying to optimize the performance of an application. It is best to not try to perform too many streneous activities at once on 4D. This can increase the load on the system and cause competition for resources which may impact the overall performance of the 4D database.

For example, with the startup. The simplest implementation of stored procedures is to initiate the procedures in the On Startup database method as a new process. It can be tempting to just run each new process one after another in the Startup database method:

$procNum1:= New Process("StoredProc1";0)
$procNum2:= New Process("StoredProc2";0)
$procNum3:= New Process("StoredProc3";0)

However, this will be executed quickly and each process will be started almost simultaneously even if there are some other executions in between the calls. Depending on what the procedures do, typically it runs once or performs some initialization calls before delaying for a specificed amount of time. The initial call to each stored proceedure can be streneous if too many are called on a machine without the needed resources. On a server machine, after the On Server Startup completes, clients are allowed to connect, this can add additional load if many users attempt to connect immediately.

If issues are found with performance during starting up 4D, it can be beneficial to investigate the processes and add some artificial delays with the stored procedures, similar to how Windows allows Services to have an "Automatic" start and an "Automatic (Delayed Start)" setting. This will allow the machine to start up prioritizing the Services set to "Automatic" and then start the delayed start services after.

Some suggestions are:
- Allow all of the Stored Proceedures to complete their initialization before allowing users to connect
- Stagger the startup of proceedures by adding delays to prevent them from running simultaneously
- Perform some optimization of the code by investigating what is causing the most impact
- Add more resources to the environment