Closed thias closed 2 years ago
Hi @thias ,
Many thanks for raising this issue with us. We have identified this as a restriction when using our Detection module under a process manager such as Apache MPM or php-fpm. When the Device Detection engine module is loaded in the main process, a pool of the data file handles is created. So when the process manager spawns child processes in response to incoming requests by forking the main process, this pool is copied to the child processes. As you have observed, when calling refreshData() in a child process, only the copied file handles of that child process is updated but not the parent process’s pool.
For now the only way to load the new data file is to restart the php-fpm service. One approach to help with restarting your service in production environment with a minimum impact is to maintain a production and a deployment slot so that you can start a new service with a new data file in a deployment slot. When the deployment slot is fully ready, swap it with production slot. A further remedy could be done is to maintain multiple production nodes and use a traffic manager to direct the requests to other nodes while the swap is being performed.
Also please make sure to use MaxPerformance profile. We designed our API to allow different performance profiles, to offer the user the ability to trade off between performance and memory usage, while also scaling well in highly concurrent environments. In other profiles such as Balanced, BalancedTemp, LowMemory or Default, only a part of the data file is loaded into memory so from time to time, calls to read data from disk are required. This call uses file handles from the file handle pool mentioned above, which was designed to optimize performance. Since the file handles pool is copied to the child processes, this causes the file handles to be shared. When multiple processes call to load data from a file using shared file handles, problems could occur such as file position being changed unwantedly by other child processes.
Moving forward, we will revisit the design of our Detection module and investigate changes required to help with these limitations.
Kind regards, Tung.
Closed as this has been identified as a restriction to certain working environments. Improvement will be invested but not at this point.
This is somewhat related to #2 and is something I had already reported directly to support.
We are using php-fpm, and the module and data file get loaded at startup. From there I've been told to use the
refreshData()
function to start using the new data after the data file gets updated.But this doesn't work as expected with php-fpm, since it's isolated to the currently php-fpm forked process (we have up to 1500 per server) and doesn't get applied to the master php-fpm process. So even somehow managing to run
refreshData()
from within all running processes wouldn't be enough.This makes it virtually impossible to use updated data files from php-fpm without having to fully restart the whole service, which is not something acceptable in most production environments, ours included.
Having a least the master process periodically check if the data file has changed could be enough, as all child php-fpm processes would eventually start using the new file once they reach their maximum executions and get replaced.
These are my original findings (the concurrency has since been made configurable, and the default of 10 can be lowered to 1):