我的服务器使用来自内部Web服务的数据来构建其响应,基于每个请求.我正在使用Apache HttpClient 4.1来发出请求.每个初始请求将导致对Web服务的大约30个请求.其中,4 - 8最终将插入CLOSE_WAIT中的插座,这些插座永远不会被释放.最终这些卡住的套接字超过了我的ulimit,我的进程耗尽了文件描述符.
我不想只提高我的ulimit(1024),因为这只会掩盖问题.
我转移到HttpClient的原因是java.net.HttpUrlConnection的行为方式相同.
我已尝试按请求移动到SingleClientConnManager,并在其上调用client.getConnectionManager().shutdown(),但套接字仍然卡住了.
我是否应该尝试解决这个问题,以便在没有运行请求时最终得到0个开放套接字,或者我应该专注于请求持久性和池化?
为清楚起见,我提供了一些可能相关的细节:
操作系统:Ubuntu 10.10
JRE:1.6.0_22
语言:Scala 2.8
示例代码:
val cleaner = Executors.newScheduledThreadPool(1)
private val client = {
val ssl_ctx = SSLContext.getInstance("TLS")
val managers = Array[TrustManager](TrustingTrustManager)
ssl_ctx.init(null, managers, new java.security.SecureRandom())
val sslSf = new org.apache.http.conn.ssl.SSLSocketFactory(ssl_ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)
val schemeRegistry = new SchemeRegistry()
schemeRegistry.register(new Scheme("https", 443, sslSf))
val connection = new ThreadSafeClientConnManager(schemeRegistry)
object clean extends Runnable{
override def run = {
connection.closeExpiredConnections
connection.closeIdleConnections(30, SECONDS)
}
}
cleaner.scheduleAtFixedRate(clean,10,10,SECONDS)
val httpClient = new DefaultHttpClient(connection)
httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY), new …
Run Code Online (Sandbox Code Playgroud) 我已经阅读了所有文档和LFE的大部分来源.所有演示文稿都强调传统lisp角色中的基本lisp - 一般问题解决,Hello world和语法模拟宏.
有谁知道LFE如何处理消息传递原语?要指定更精确的问题,您将如何表达此erlang:
A = 2,
Pid = spawn(fun()->
receive
B when is_integer(B) -> io:format("Added: ~p~n",[A+B]);
_ -> nan
end
end),
Pid ! 5.
Run Code Online (Sandbox Code Playgroud)
然后,你知道,它总结了一些关于添加了一些数字而答案是7的东西.