For performance reasons I need to run multiple instances of an app, pinned to CPU, listening on different ports. An HAProxy TCP load balancer sits in front of them to distribute the traffic.
This is done to prevent any thread context switching and to enforce a shared-nothing design (so no need for any sort of locks within an application, assuming it is single threaded).
So that means on a server with 64 CPUs, I may have HAProxy pinned to CPU 0 and then 63 instances of my app each pinned to separate CPUs (1-63).
Obviously that is quite complex to manage in terms of startup, restart, shutdown, etc.
I was wondering if there is any way I could use systemd to handle this complexity for me.
I know that if I defined HAProxy as a unit and then stated it Requires the other apps it needs to talk to, it could solve the start up problem, e.g.
Require=app1,app2,.....,app63
I could do
systemctl start myhaproxy
and it would first start the 63 instances it requires (assuming each of them is defined as a separate systemd unit during app installation).
However, I am wondering if there is anyway I could get this to also work for restart and shutdown.
So if I do:
systemctl stop myhaproxy
I would like it to automatically shutdown all the 63 instances of the app it talks to.
And if I do
systemctl restart myhaproxy
then I would like it to first restart all the services listed in Require before restarting itself at the end.
Is that possible? Or does that go beyond what systemd can provide?