对 .jsp 页面 (Tomcat7) 和 .cfm 页面 (Coldfusion10 Enterprise) 运行“ab”。ab 正确记录了 .jsp 页面的保持活动结果,但记录了 .cfm 页面的保持活动结果。看来 CF 不支持保持活动?可能是设置问题?我在 Google 上搜索过,并在 CF 管理员中查找过,但无济于事。
笔记: .jsp 在单独的 tomcat7 实例下运行。CF10 安装为独立服务器,并带有自己的底层 tomcat 服务器。目前不关心“每秒请求数”,希望有人能帮助我理解为什么 CF 的“Keep-Alive 请求数”在这里为 0?刷新时未计算 Content-Length?
(index.jsp)
# ab -kn 1000 -c 10 http://127.0.0.1:8084/
Concurrency Level: 10
Time taken for tests: 0.094 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
**Keep-Alive requests: 995**
Total transferred: 460975 bytes
HTML transferred: 212000 bytes
Requests per second: 10676.46 [#/sec] (mean)
Time per request: 0.937 [ms] (mean)
Time per request: 0.094 [ms] (mean, across all concurrent requests)
Transfer rate: 4806.23 [Kbytes/sec] received
(index.cfm)
# ab -kn 1000 -c 10 http://127.0.0.1:8501/
Concurrency Level: 10
Time taken for tests: 0.395 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
**Keep-Alive requests: 0**
Total transferred: 148148 bytes
HTML transferred: 7007 bytes
Requests per second: 2529.33 [#/sec] (mean)
Time per request: 3.954 [ms] (mean)
Time per request: 0.395 [ms] (mean, across all concurrent requests)
Transfer rate: 365.93 [Kbytes/sec] received
索引.cfm
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test</title>
</head>
<body>
<h1><cfscript> WriteOutput("Hello CF."); </cfscript></h1>
<!---
<h1><cfoutput>Hello CF.</cfoutput></h1>
--->
</body>
</html>
索引.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test</title>
</head>
<body>
<h1><% out.print("Hello JSP."); %></h1>
</body>
</html>
答案1
事实证明,CF 默认不计算 Content-Length。解决方法是计算输出长度并将其添加到 Application.cfc / onRequestEnd 下的 Content-Length 标头中。
# Application.cfc
# onRequestEnd
<cfheader name="Content-Length" value="#len(getPageContext().getOut().getString())#" />
在覆盖此标头之前,先测试一下它是否存在可能是明智之举,但就我的测试而言,它工作得很好。恕我直言,这应该是 CF 中的自动魔法功能,我想不出你不想计算 Content-Length 并将其添加为标头的理由。
值得一读: http://docstore.mik.ua/orelly/java-ent/servlet/ch05_03.htm