ServicePoint在stream.close()之后保持连接 [英] ServicePoint holds connection after stream.close()

查看:75
本文介绍了ServicePoint在stream.close()之后保持连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我有一个多线程的c#方法,它将请求发布到网址并读取响应。  ServicePoint.MaxConnections设置为10. 添加了Console.WriteLine语句以监视ServicePoint.CurrentConnections。 在所有线程
完成并关闭了流和resonseStream之后,ServicePoint.CurrentConnections仍然是3,这是正在运行的线程数。

I have a multithreaded c# method which posts a request to a url and reads the response.  The ServicePoint.MaxConnections is set to 10.  Console.WriteLine statements were added to monitor the ServicePoint.CurrentConnections.  After all threads have completed and have closed the stream and the resonseStream, the ServicePoint.CurrentConnections is still 3 which is the number of threads that were running.

我带来的原因这就是如果其中一个线程花了很长时间获取数据,有时候另一个线程似乎会排队,等待第一个完成。 这并不总是会发生。  ServicePoint.SupportsPipeline为true,因此请求
不应该在客户端排队。

The reason I bring this up is that if one of the threads takes a long time get the data, sometimes another thread will seem to queue, waiting for the first to finish.  This doesn't always happen.  ServicePoint.SupportsPipeline is true, so the requests should not be queueing on the client side.

有谁知道如何让请求不排队? 注意:ServicePoint.MaxConnections设置为10.

Does anyone know how I can get the requests to not queue?  Note: ServicePoint.MaxConnections is set to 10.

以前这似乎有效(不是100%肯定),现在它无法正常工作。 我的xp sp2已更新...注册表项:MaxConnectionsPer1_0Server和MaxConnectionsPerServer是否可能重置为2(键设置为10)?

Previously this seemed to work (not 100% sure), and now it is not working.  My xp sp2 has been updated...is it possible that the registry keys: MaxConnectionsPer1_0Server and MaxConnectionsPerServer were reset to 2 (keys were set to 10)?

感谢任何帮助。

oodeveloper

oodeveloper

推荐答案

我认为如果在制作之前在请求对象上设置HttpWebRequest.KeepAlive = false请求后,一旦收到回复,Socket就不会保持打开状态。

I think if you set HttpWebRequest.KeepAlive = false on your request object before making the request, the Socket will not stay open once you have received the response.

> ServicePoint.CurrentConnections仍然是3,这是正在运行的线程数。

> the ServicePoint.CurrentConnections is still 3 which is the number of threads that were running.

这听起来不像通常会出现问题。 人们倾向于遇到最多的问题是需要在应用程序或Web配置文件中以
增加 maxconnection。  "保持活力"其中包含CurrentConnections>在实际关闭连接后的一段时间内,重复使用0通常可以自动正常工作并提高性能。

This doesn't sound like it normally would be a problem.  The issue people tend to run into the most is a need to increase the maxconnection in the app or web config file.  The "keep alive" which holds CurrentConnections > 0 for reuse for a time period after you actually close the connections usually works fine automatically and improves performance.

>另一个线程似乎排队,等待第一个完成

> another thread will seem to queue, waiting for the first to finish

这可能是需要增加配置文件中的maxconnection的症状。 通常,这也是由服务器应用程序访问的资源(例如数据库)中的阻塞或延迟引起的。

This may be a symptom of a need to increase the maxconnection in the config file.  Commonly, this is also caused by blocking or delay in a resource that the server application accesses (such as a database).

 

这篇关于ServicePoint在stream.close()之后保持连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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