在ColdFusion中维护出站TCP连接池 [英] Maintain Outbound TCP Connection Pool in ColdFusion

查看:152
本文介绍了在ColdFusion中维护出站TCP连接池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从ColdFusion应用程序中大量使用RESTful API。

I'm looking to make heavy consumption of a RESTful API from a ColdFusion application.

我不是CF专家,但我期待重复的cfhttp呼叫将成为瓶颈,因为我相信每个结果都会建立连接,请求发送,响应接收和连接断开。

I'm not a CF expert but I'm anticipating the repeated cfhttp calls will become a bottleneck as I believe that each results in a connection being established, request sent, response received and connection torn down.

我很好奇 - 如何维护一个连接池请求可以通过发送以避免重复建立/拆除?

I'm curious - is there a way to maintain a connection pool that requests could be sent through to avoid the repeated establish/tear down?

ColdFusion服务器是否提供了这样一个设施,我只是不

Does the ColdFusion server provide such a facility that I just don't know about (we're using CF 8) or can I write a java custom tag that could maintain the pool?

当然还有其他人遇到过这个问题。

Certainly someone else has encountered this.

推荐答案

我想你可能实际上可以通过使用Keep-Alive请求头与您的cfhttp调用。例如:

I think you might actually be able to do this by using the "Keep-Alive" request header with your cfhttp calls. For example:

<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>

我没有测试过,但在理论上它应该保持连接的后端开放你做出每个请求(假设后端允许这个,并且连接之间的延迟没有触发超时)。您应该确保您的API响应包含Content-length标头,以便客户端(您的cfhttp代码)知道每个请求已完成。您将需要发出一个明确的关闭,因为我已经显示,以防止不必要的开放连接到后端。

I haven't tested this, but in theory it should keep the connection to the back end open while you make each of those requests (assuming the backend allows for this and the delay between connections hasn't triggered a time-out). You should be sure that your API response includes a "Content-length" header so that the client (your cfhttp code) will know when each request has completed. You will want to issue an explicit "close" as I've shown to prevent unneeded open connections to the backend.

这篇关于在ColdFusion中维护出站TCP连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆