I am using GEKKO to study the effect of MPC and MHE on building energy use. To get a performance increase i now switched to a dedicated solving server by setting m.GEKKO(remote=True, server='http://10.0.0.10'). This server is a freshly installed Ubuntu 20.04.1 machine hosting just the linux APmonitor server. Everything works fine so far except that my control and also estimation cycle times increase linearly with every additional solve for the remote solving option. I use my building model with IMODE=6 for MPC and IMODE=5 for MHE and both show the same behaviour.
In the following figure you can see the cycle times and solve times for local and remote solve. These tests were conducted with the IPOPT MA57 Solver, but others show the same behavior. My program does not change except for switching from remote=False to my solving server remote=True, server='http://10.0.0.10'.
In addition, I have added the timing diagnosis output of the solver after a few steps (left) and after a few hundred steps (right). It clearly shows a much higher system time but very similar solving time but I could not find the culprit here either. Except for this test I have always set DIAGLEVEL=0 and m.solve(disp=False) to reduce the console output.
However, re-initializing the GEKKO model and starting again immediately drops the cycle times. This shows that it is not a problem with the server’s compute capacity reducing over time. For me this looks like some file the process reads and/or writes bloats with the number of iterations but I could not find anything significant in the current model directory. Maybe someone knows the problem and can help me with this one.
Edit 1:
Trying the example script provided by John Hedengren in his answer showed a different result for me. The following picture again shows the same linearly increasing behavior. I ran this test with a different physical machine, also using a different physical network adapter at the solving server. Previously i even switched the physical machine of the solving server. Tested with Python Versions 2.7.16, 3.7.7 and 3.8.5.
For me this leads to the conclusion that this situation is not caused by my MPC application. It also doesn't seem to be related to a hardware problem at the client, the network , or the server. IMHO it looks like a server software problem.
A few specs here:
- Ubuntu 20.04.1
- Apache 2.4.41
- PHP 7.4.3
- APMonitor, Version 0.9.2
Edit 2:
After using John Hedengrens sample problem to test multiple solving servers i came to the conclusion that the behavior of rising cycle times is not unique to my Ubuntu linux setup. Here a few examples:
Official APMonitor solving server (Web)

to make it make it more obvious i removed the oulierers in the next picture

In my case a cycle time increase of about 1 second per 1000 cycles (for this sample problem) happens regardless of the used remote solver (local solve is always fine). The effect of this steady cycle time increase is not as prominent if the solve/cycle times are longer anyway or the number of cycles is not high enough. For my application however this is very problematic as i have to run about 40k cycles as fast as possible.
Edit 3:
Implementing the changes to gekko.py and apm_line.php John Hedengren suggested in his answer fixed the problem partly but not entirely. There is still an increase in cycle time. Once again, looking closer and longer reveals the issue. The following image shows the output of the usual test script, this time for the updated versions of gekko.py and apm_line.php a linux APM server (Windows shows same behavior) and 5k steps. Looking very closely you can even see this effect in the diagram (1k runs) John posted in his answer edit.








