Question
· Oct 4, 2023

Is there a class that implement a connection pool ? If not, is it possible to implement one ?

I have some code that fire this kind of request very often : 

set request = ##class(%Net.HttpRequest).%New()
set request.Server = ... //always the same 
set request.Location = ... //always the same 
do request.EntityBody.Write(...) //this is different from one request to another
do request.Post() 

If it was called in a loop I could move the HttpRequest instantiation outside, unfortunately this is not the case. The code is called from lot of different places.

I have been wondering if there is a class in IRIS that already implement a connection pool
Eg: a set of connections is maintained and stay open. They can be reused between requests.

Some like that : 

set request = connectionPool.Acquire() //return HttpRequest instance
//...
do request.EntityBody.Write(...)
do request.Post() 
//...
do connectionPool.Release(request)

If that does not exists, would it be difficult to implement one (is this something possible ?) (eg: using some mutexes for synchronization)

EDIT: 

I just realized that (AFAIK) it's not possible to share object instances across processes in IRIS.
So I cannot see a simple way to reuse connections by simply having a class that maintain a set of HttpRequest instances and share them.
One way could be to create a single job that hold all connections and perform the actual GETs / POSTs for someone else (another process) then return result (typically a string).

Product version: IRIS 2021.1
Discussion (3)1
Log in or sign up to continue

Look into using Interoperability. The classes EnsLib.REST.Operation and EnsLib.HTTP.GenericOperation should do what you are looking for depending on if you are calling a REST service or it is plain HTTP

We have several business operations that use EnsLib.REST.Operation, each with pool sizes of between 2 and 60. Providing the http response indicates the connection can be maintained, they will keep the connection open.