手柄数量多 [英] High number of Handles

查看:85
本文介绍了手柄数量多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.在我的公司中,我们有一个Windows服务应用程序,该应用程序使用Socket事件OnDataArrival来处理到达的数据,一次依靠多个线程功能处理多个套接字请求.

尽管系统运行正常,但服务器管理员抱怨应用程序进程使用了​​大量的句柄.即,当您打开Windows任务管理器并检查句柄"列时,该进程的句柄数约为30000.我检查了一些来源,单个进程的合理句柄数约为3000,而8000已经是一个很高的数字.我太过分了.

有人使用OS句柄将.net线程和事件与某些人相关吗?我需要一些有关如何减少该过程的处理数量的提示.我可能应该以良好的线程实用性重新执行该应用程序(实现非常古老),但是我需要用于实际服务的更快的解决方案.

Hi there. In my company, we have a windows service app that relies on multiple threads functionality to process many socket requests at a time, using the Socket events OnDataArrival to proccess the arriving data.

Although the system is working properly, the server administrator is complaining that the app process is using a very high number of handles. That is, when you open the Windows Task Manager and check for the Handles column, the number is around 30000 handles for the process. I''ve checked some sources and a reasonable number of Handles for a single process is around 3000, and a 8000 is already a very high number. I''m way too over this.

Do anyone has some good sources relating .net threads and events with the use of OS handles? I need some hints on how to low the number of hanldes for the process. I should probably re-do the app with good threading pratices (the implementation is very old), but I need a faster solution for the actual service.

推荐答案

您可能并没有真正使用那么多的句柄,但是在代码中泄漏了一些句柄未正确释放的地方.

You''re probably not really using that many handles, but have a leak in your code somewhere where handles are not being released properly.




我还没有做过任何大规模的套接字工作,但是我了解您不需要的.NET套接字根本没有显式线程; BeginConnect,BeginAccept或BeginReceive是异步处理的,事件是在其他一些线程上处理的,通常从ThreadPool中获取.因此,我希望每个套接字只需要一个(或几个?)句柄.

:)

Hi,

I haven''t done any mass socket stuff, however the way I understand .NET sockets you don''t need explicit threads at all; a BeginConnect, BeginAccept, or BeginReceive is handled asynchronously, and the events get handled on some other thread, typically taken from the ThreadPool. So I expect you only need one (or a few?) handles per socket.

:)


莱昂纳多·穆齐(Leonardo Muzzi)写道:
Leonardo Muzzi wrote:

大约有30000个处理程序的句柄

around 30000 handles for the process



太多了. AFAIK,句柄计数包括文件句柄,线程,互斥量,信号量等.查看应用程序源并确保正确释放资源.任何资源的寿命都不应超过预期.获取一些内存分析器,并分析对象分配和GC活动.

其他方法是记录应用程序活动并分析日志.这将帮助您了解它在哪个区域上花费了更多时间,以及哪些资源没有得到正确释放.



Thats too much. AFAIK, the handles count includes the file handles, threads, mutex, semaphore etc. Look at the application source and ensure the resources are properly released. No resource should live longer than expected. Get some memory profilers and analyze the object allocation and GC activities.

Other way is to log the application activities and analyze the log. This will help you to understand which area it is spending more time and what resources are not getting released properly.

Leonardo Muzzi写道:
Leonardo Muzzi wrote:

windows服务应用程序依靠多个线程功能来一次处理多个套接字请求,

windows service app that relies on multiple threads functionality to process many socket requests at a time,



您如何执行此操作?每个请求每个线程?如果是,请考虑使用套接字类中提供的异步方法.异步方法使编写高效线程应用程序成为可能.

此处 [



How are you doing this? Each thread per request? If yes, consider using asynchronous methods provided in the socket class. Asynchronous methods makes it possible to write highly thread efficient applications.

Here[^] is a decent MSDN article which takes the subject in detail.

:)


这篇关于手柄数量多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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