This content has been marked as final. Show 1 reply
so my only option is to start multiple processPresumably you really do me a "process" in that the OS will be running multiple instances of the executable.
Each of the server processes require an init function to be run before providing the service. How do I setup the server processes to continue to run in memory listening for a a service request after running the init processes.Your request handling proceeds as follows.
1. Is the process already in the collection (a static collection you keep somewhere.) If so get it.
2. If no, then create it, call init() put it in the collection.
3. Now run the request with the process which you will have either from step 1 or 2.
2. Is there a better implementation of what I am trying to do?You way is probably best. There are different ways to do it and other considerations - those follow.
You only need one port. Your caller(s) shouldn't care how many are running. They just send a request and get a response. Your server hands off the request to the next available process.
Presuming processing takes a long time otherwise why not just queue up the requests and run for one process?
You can provide configuration values to
1. Start a minimum number on server start up. This is advisable if init takes a while.
2. Stop some if they are idle for a set period of time
3. Have a maximum after which requests are rejected or queued (last part could be configured as well.)
The process might just stop or might return an error that indicates it should be stopped. If so code for that and then remove it from the collection.
Insure that the server shuts down gracefully and it MUST stop the running processes.
Log the following
- When you start a process
- When you stop a process. And why it was stopped: idle or error
- When you get a request.
- How long it took to process the request
- If the request result was an error or not.