了解ColdFusion中的持久HTTP连接 [英] Understanding Persistent HTTP Connections in ColdFusion

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

问题描述

结论:我试图了解ColdFusion是否能够通过CFHTTP标记在单个请求之外使用持久性http连接。这篇文章的一部分是我发现/尝试了什么。

Bottom Line: I'm trying to understand if ColdFusion is able to make use of a persistent http connection outside of a single request via the CFHTTP tag. Some of this post is "what have I found/tried."

我的系统:
CF10
IIS7.5
Windows 7

My system: CF10 IIS7.5 Windows 7

我目前正在通过HTTP Rest接口连接到ElasticSearch,该接口将具有大量的cfhttp调用。在这种情况下,ColdFusion是Client,ElasticSearch是服务器。按照建议,我传递了keep-alive标头以及cfhttp请求,但发现CFHTTP似乎总是在它之后添加一个关闭产生这个标题:

I am currently hooking into ElasticSearch via an HTTP Rest interface which will have a magnitude of cfhttp calls. In this case, ColdFusion is the Client and ElasticSearch is the server. As recommended, I passed the keep-alive header along with the cfhttp request, but found the CFHTTP seemed to always add a close right after it resulting in this header:

<!--- Calling tag --->
<cfhttp url="loc.mysite.com?endpoint" 
    method="POST"
    result="ret">
<cfhttpparam type="HEADER" name="Keep-Alive" value="300">
<cfhttpparam type="HEADER" name="Connection" value="keep-alive">
<cfhttpparam type="xml" value="#body#" />
</cfhttp>
<!--- Results in this  header. (dumping getHTTPrequestdata() on a dummy page) --->
connection: keep-alive,closed

首先,我无法弄清楚如何防止接近发生。

First, I cannot figure out how to prevent the close from occurring.

其次,我无法弄清楚ColdFusion是否会重复使用该连接,即使它是在同一请求期间或在此请求之外没有关闭的情况下发送的。显然,这与Java在这一点上与OS的交互方式有关。最初,我认为它将由ColdFusion的魔力处理,但我开始认为它没有使用任何花哨的Java池化魔法。

Second, I cannot figure out if ColdFusion would reuse the connection, even if it is sent without the close during the same request or outside of this request. Clearly this has to do with how Java is interacting with the OS at this point. Initially, I thought it would be handled by the magic of ColdFusion, but I'm beginning to think that it is not using any of the fancy Java pooling magic.

第三,我在ColdFusion中找不到关于http连接池的任何文档。它确实有数据库连接池,但http池可能是一个相对较新的要求。

Third, I cannot find any documentation on http connection pooling in ColdFusion. It does DB connection pooling just fine, but http pooling is probably a relatively new requirement.

第四,我发现CFX_http5仍在使用Tomcat在ColdFusion 10中工作(什么是机会)。虽然它擅长多线程请求,但很少提及如何使用keep-alive。没有购买它,我无法在循环内测试它。它不会添加关闭标头。它会像我期望的那样发送保持活动。

Fourth, I have found the CFX_http5 is still working in ColdFusion 10 with Tomcat (what are the chances). While it is good at multithreading requests, there is little mention of how the keep-alive is used. Without purchasing it, I can't test it inside a loop. It does not add the close header. It sends keep alive as I would expect.

第六次(自首次发布以来编辑很多)
第六,Windows有默认的临时或短暂端口数它可以利用产生新的出站TCP连接。默认情况下,一旦打开一个连接,Windows将使其保持活动状态两分钟(尽管它刚刚放弃并占用了此时的空间)。这是一个TCP配置,因此http标头不会直接在这里播放。可用端口的默认端口数为5,000个,减去1024个= 3076个端口。这意味着一个盒子上的所有ColdFusion实例在任何给定的两分钟窗口中最多可以产生3076个http请求,而不会在可用的连接端口上等待。如果太多请求被淹没(我不知道在什么时候),您将收到连接已关闭错误。这让我想起原始级别的垃圾收集。因此,升级注册表中的级别(请参阅后面)并避免这些扼流圈,但您仍然遇到连接设置/拆除延迟,此解决方案无法扩展。

Sixth (edited heavily since initial post) Sixth, Windows has a default number of temporary or "ephemeral" ports that it can make use of to spawn new outbound TCP connections. By default, once a connection is opened, Windows will keep it alive for two minutes (although it's just abandoned and taking up space at this point). This is a TCP configuration, so http headers aren't directly at play here. The default number of ports available is 5,000 less 1024 = 3076 ports. This means all ColdFusion instances on a box could make up to 3076 http requests in any given two minute window without being choked waiting on an available connection port. If too many requests are flooded (I have no idea at what point), you will receive a "connection closed" error. This reminds me of garbage collection at a primitive level. So, up the level in the registry (see post) below and you avoid these chokes, but you are still experiencing connection setup/tear down delays and this solution will not scale.

更新:CFX_HTTP5确实支持单个ColdFusion请求中预期的保持活动和持久连接。我的ElasticSearch端点的150K查询测试先前在15分钟内完成。使用CFX_HTTP5,它在4分钟内运行。此外,我能够将注册表切换回默认端口数。下一步是弄清楚HTTPComponents是否有效。我已经接近工作了。

Update: CFX_HTTP5 does support keep-alive and persistent connections as expected within a single ColdFusion request. My 150K query test to my ElasticSearch endpoint previously ran in 15 minutes. With CFX_HTTP5, it ran in 4 minutes. In addition, I was able to switch the registry back to the default number of ports. The next step is to figure out if HTTPComponents will work. I have that nearly working.

更新2::使用下面建议的HTTP组件构建自定义http调用。我使用了默认设置的基本连接池管理器。我还没试过调整它。这个过程在5分钟内结束,比cfx_http5慢一点,但仍然比cfhttp快很多。另外,我还没有完成涉及多个ColdFusion请求的测试来真正测试连接池。

Update 2:: Built out a custom http call using the HTTPcomponents suggested below. I used a basic connection pool manager with default settings. I have not attempted to tune it yet. The process finished in 5 minutes which is a tad slower than cfx_http5, but still a lot faster than cfhttp. In addition, I have not done tests involving multiple ColdFusion requests to really test the connection pool.

更新3:我确认HTTPComponents确实是设置适当的连接池。但是,由此有责任正确管理这些连接和池本身,以确保它是系统资源的良好管理者。我能够从几个不同的同时请求中运行数百万个HTTP请求,同时只打开少量的HTTP连接。从日志中,我能够看到有多少连接正在使用,空闲或旋转。这真的不是那么多代码,项目背后的人都有很棒的文档。

Update 3: I verified that HTTPComponents is indeed setting up a proper connection pool. However, with this comes a responsibility to properly manage those connections and the pool itself to ensure it is a good steward of system resources. I was able to run several million HTTP requests from several different simultaneous requests while only opening a small handful of HTTP connections. From the logs, I was able to see how many connections were being used, idle, or spun-up. It's really not that much code either, the people behind the project have great documentation.

HTTPComponents Connection Pool:
Single request, unlimited CFHTTP to same connection = single open TCP connection
N-requests = <N open TCP connections. 

CFHTTP
N-CFHTTP calls + N-CFHTTP calls in previous 60 seconds = open TCP connections

参考:
我确实发现Java有这个可用,这表明它是可能的,但谁知道Adobe如何实现CFHTTP
java中持久的Http客户端连接

CFX_http5自定义标记使用C ++进行自定义http连接,因此它可能理解连接池。
http://www.cftagstore.com/tags/cfxhttp5.cfm

CFX_http5 custom tag uses C++ for custom http connections, so it's possible that it understands connection pooling. http://www.cftagstore.com/tags/cfxhttp5.cfm

相关问题:
在ColdFusion中维护出站TCP连接池

关于Windows Max Connections / Ephemeral端口
http://kb.globalscape.com/KnowledgebaseArticle10438.aspx

About Windows Max Connections/Ephemeral ports http://kb.globalscape.com/KnowledgebaseArticle10438.aspx

推荐答案

我99%确定CFHTTP不支持持久连接,它只是没有设置来处理它。我认为你真的需要一个不同的API来处理连接和个别请求。我没有拿到CF10,但CF9有一个2001年的HTTPClient版本,所以我希望CF团队更新CF10!

I'm 99% sure that CFHTTP does not support persistent connections, it's just not set up to deal with it. I think really you'll need a different API to handle both the connection and individual requests. I've not got CF10 to hand, but CF9 has a version of HTTPClient from 2001, so I hope the CF team updated with CF10!

我希望使用一个基于Java的HTTP库,例如 HTTPClient 。从功能列表:连接管理支持在多线程应用程序中使用。支持设置最大总连接数以及每个主机的最大连接数。检测和关闭过时连接

I would look to use a Java-based HTTP library, such as HTTPClient. From the Features list: "Connection management support for use in multi-threaded applications. Supports setting the maximum total connections as well as the maximum connections per host. Detects and closes stale connections"

这篇关于了解ColdFusion中的持久HTTP连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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