I need to limit the number of instances of an Agent. Is the following code the best technique?
If counter > 50 then exit sub
Counter++
Call WS '//this could time out after 110 seconds
Counter--
This meta code will be written in LOTUSSCRIPT (the agent is already in LS). Concerning the programmatic aspect of the counter, what is the best approach (in heavily concurrent calls):
- Lock document counter doc then save (loop on doc.lock)
- save doc and test save conflict (loop on whole get doc if doc.save false, false)
- LockID=CreateLock(LockName as String) then update (loop on createLock)
- any better idea?
I have already read: Are web services processed sequentially or in parallel? http://www-10.lotus.com/ldd/ddwiki.nsf/dx/sequential-numbering.htm a ten years old still very accurate document http://www.eview.com/eview/volr6.nsf/0/62B3A667117B484385256F3300576ECF/$File/Guide%20to%20Document%20Locking%20SO%20604.pdf
More about the Context: An agent in a cluster Web Domino server is heavily called (300+ called per minutes during peaks). This agent calls a Domino consumer to another system WS.
Sometime the external system has problems and don't return response "in a reasonable amount of time" (I get Time out after about 110 sec).
The problem: when this appends, all the workers (threads of http, determined by Number active threads: in the server document configuration) are waiting for a response. As the Domino server stops to responds! After the stalled agents timed out, the next call to the agent starts to wait for time out… causing a hugh queue of requests until crashing the server.
To prevent the agent to exhaust the resources (the threads/workers in this case) I'm planning to increment a counter at the beginning of the agent and decrement it when the agent finished. At any time I should have the amount of running instance of the agent. A simple test at the beginning of the agent will make it.
N.B. Using wsConsumer.Settimeout( ms) could lower the time the agent waits but can solve the problem.