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

查看:11
本文介绍了了解 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."

我的系统:CF10IIS7.5视窗 7

My system: CF10 IIS7.5 Windows 7

我目前正在通过一个 HTTP Rest 接口连接到 ElasticSearch,该接口将有大量的 cfhttp 调用.在这种情况下,ColdFusion 是客户端,而 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 在这一点上如何与操作系统交互有关.最初,我认为它会由 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 连接池的文档.它可以很好地执行 DB 连接池,但 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.

更新:在单个 ColdFusion 请求中,CFX_HTTP5 确实支持保持连接和持久连接.我对 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 有这个可用,这表明它在可能的范围内,但是谁知道 Adob​​e 是如何实现 CFHTTPjava中的持久Http客户端连接

Reference: I did find that Java has this available, which shows that it's in the realm of possibility, but who knows how Adobe has implemented CFHTTP Persistent Http client connections in java

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 最大连接数/临时端口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天全站免登陆