Maintain outbound TCP connection pool in ColdFusion

I want to use a large number of RESTful APIs from a ColdFusion application.

I am not a CF expert, but I expect that repeated calls to cfhttp will become a bottleneck, since I believe that every result is a connection, send a request, receive a response and disconnect.

I am curious - is there a way to maintain a pool of connections that can be sent to avoid re-establishment / failure?

Does the ColdFusion server provide a tool that I just don’t know about (we use CF 8), or can I write a custom java tag that could support the pool?

Of course, someone else came across this.

+2
source share
2 answers

Unfortunately, I think the answer is no, especially because of your requirements. This is simply not how REST works; and limitation is the side of the API, not the ColdFusion issue.

You can do something similar, assuming that you also have control over the API, but that will not be REST.

0
source

I think you can really do this using the "Keep-Alive" request header with your cfhttp calls. For instance:

<cfloop from="1" to="50" index="i"> <cfhttp url="http://mysite.com/getPage.cfm?i=#i#" method="get"> <cfif i LT 50> <CFHTTPPARAM type="HEADER" name="Connection" value="Keep-Alive"> <cfelse> <CFHTTPPARAM type="HEADER" name="Connection" value="close"> </cfif> </cfhttp> <cfdump var="#cfhttp.filecontent#"> </cfloop> 

I have not tested this, but theoretically it should support the connection to the back side when you make each of these requests (assuming the backend allows this, and the delay between the connections did not cause a timeout). You must be sure that your API response includes a "Content-length" header so that the client (your cfhttp code) knows when each request will be executed. You will want to post an explicit β€œclose”, as I showed, to prevent unnecessary open connections to the server.

0
source

Source: https://habr.com/ru/post/948581/


All Articles