多线程tcp / ip服务器大页面文件 [英] multithreaded tcp/ip server large page file

查看:64
本文介绍了多线程tcp / ip服务器大页面文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个2005 TCP / IP服务器,它创建一个新线程来处理每个

传入的TCP / IP请求。一旦请求被

线程应答,TCP / IP套接字就会断开,子/线程结束。这个

计划最初写于2003年,我在2005年早些时候重写了这个

年。我不知道这已经持续了多长时间,但我们今天刚刚注意到这个程序正在使用虚拟内存。真实的

内存非常低。该程序已经运行了大约2周。

关闭它并重新启动它将虚拟内存降低到几乎没有b $ b。


我不知道导致这个问题的原因,但我总是想知道那些没有被清理的

线程。我使用thread.start启动它们

但没有结束它们。我被告知VB会清理它们。


从2003年到2005年没有变化的一件事是

Thread.ApartmentState = ApartmentState.STA。 2005年说它已经过时了,但程序运行了,所以我忽略了它的警告。这会导致

问题吗?


有什么想法吗?

I have a 2005 TCP/IP server that creates a new thread to handle each
incoming TCP/IP request. Once the request has been answered by the
thread the TCP/IP socket is disconnected and the sub/thread ends. This
program originally written in 2003 and I rewrote it in 2005 earlier this
year. I don''t know how long this has been going on but we just noticed
today that the program was using over a gig of virtual memory. Real
memory was quite low. The program had been running about 2 weeks.
Shutting it down and restarting it dropped the virtual memory to almost
nothing.

I don''t know what causes this problem but I''ve always wondered about the
threads that end not being cleaned up. I use thread.start to start them
but nothing to end them. I''ve been told VB will clean these up.

One thing that didn''t change over from 2003 to 2005 was
Thread.ApartmentState = ApartmentState.STA. 2005 says it obsolete but
the program runs so I ignored it''s warning. Could this be causing a
problem?

Any ideas?

推荐答案

我的研究表明,没有必要的结束线程类型声明

- 就像我被告知的那样。当包含我的

线程的子句结束时,线程结束。由于ApartmentState.STA已经过时但不是非法b $ b非法,我怀疑它是否会导致虚拟内存增长。还有什么呢?
它是什么?


cj写道:
My research suggest that there is no end thread type statement
necessary--just like I''ve been told. When the sub that comprises my
thread ends the thread ends. As ApartmentState.STA is obsolete but not
illegal I doubt it is causing virtual memory to grow. What else could
it be?

cj wrote:

我有一个2005 TCP / IP服务器,它创建一个新线程来处理每个

传入的TCP / IP请求。一旦请求被

线程应答,TCP / IP套接字就会断开,子/线程结束。这个

计划最初写于2003年,我在2005年早些时候重写了这个

年。我不知道这已经持续了多长时间,但我们今天刚刚注意到这个程序正在使用虚拟内存。真实的

内存非常低。该程序已经运行了大约2周。

关闭它并重新启动它将虚拟内存降低到几乎没有b $ b。


我不知道导致这个问题的原因,但我总是想知道那些没有被清理的

线程。我使用thread.start启动它们

但没有结束它们。我被告知VB会清理它们。


从2003年到2005年没有变化的一件事是

Thread.ApartmentState = ApartmentState.STA。 2005年说它已经过时了,但程序运行了,所以我忽略了它的警告。这会导致

问题吗?


有什么想法吗?
I have a 2005 TCP/IP server that creates a new thread to handle each
incoming TCP/IP request. Once the request has been answered by the
thread the TCP/IP socket is disconnected and the sub/thread ends. This
program originally written in 2003 and I rewrote it in 2005 earlier this
year. I don''t know how long this has been going on but we just noticed
today that the program was using over a gig of virtual memory. Real
memory was quite low. The program had been running about 2 weeks.
Shutting it down and restarting it dropped the virtual memory to almost
nothing.

I don''t know what causes this problem but I''ve always wondered about the
threads that end not being cleaned up. I use thread.start to start them
but nothing to end them. I''ve been told VB will clean these up.

One thing that didn''t change over from 2003 to 2005 was
Thread.ApartmentState = ApartmentState.STA. 2005 says it obsolete but
the program runs so I ignored it''s warning. Could this be causing a
problem?

Any ideas?


好吧,使用新线程处理请求是一个非常糟糕的方式。


每次你启动一个新的线程,它将占用至少1兆的
完全提交的虚拟内存。您可以在以下网址阅读关于此

的所有详细信息:
http://www.bluebytesoftware.com/blog...ed0f97ab5.aspx


你真的,真的需要使用不同的模型是你希望你的

应用程序以任何有意义的方式扩展。 Async I / O实际上是你唯一的长期解决方案。


通常情况下,你不需要关闭线程 - 它们只是在他们的时候就会消失

顶级方法退出。如果您查看应用程序,请使用Performance

计数器来判断您运行的线程数。如果这个数字非常高,那么有些东西会让线程保持打开状态。不要(不要!

真的!)只需拨打Kill Thread即可。在开放的线程上,如果是这种情况 -

找出问题所在并解决它。


你不必担心公寓状态 - 它与套接字应用无关。




-

Chris Mullins,MCSD。 NET,MCPD:Enterprise,Microsoft C#MVP
http://www.coversant .com / blogs / cmullins


" cj" < cj@nospam.nospamwrote in message

新闻:OJ ************** @ TK2MSFTNGP05.phx.gbl ...
Well, handling a request with a new thread is a pretty bad way to ago.

Each time you spin up a new thread, it''s going to take up at least 1 meg of
fully committed virtual memory. You can read all the gory details about this
at:
http://www.bluebytesoftware.com/blog...ed0f97ab5.aspx

You really, really need to use a different model is you want your
application to scale in any meaningful way. Async I/O is really your only
long term solution.

Typically, you don''t need to shutdown threads - they just go away when their
top level method exits. If you poke at your application, use a Performance
Counter to tell how many threads you''ve got running. If the number is very
high, then something is keeping the threads heald open. Do NOT (don''t!
really!) just call "Kill Thread" on the open threads if this is the case -
figure out what the problem is and fix it.

You don''t need to worry about the Apartment state stuff - it''s not relevant
for a socket app.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP
http://www.coversant.com/blogs/cmullins

"cj" <cj@nospam.nospamwrote in message
news:OJ**************@TK2MSFTNGP05.phx.gbl...

>我有一个2005 TCP / IP服务器,它创建一个新线程来处理每个传入的TCP / IP请求。一旦线程回答了请求,则TCP / IP套接字断开,子/线程结束。这个程序最初写于2003年,我在今年早些时候在2005年重写了它。我不知道这是多久了,但我们今天才注意到该程序正在使用虚拟内存。真正的记忆非常低。该计划已经运行了大约2周。关闭它并重新启动它会使虚拟内存几乎一无所获。


我不知道是什么导致了这个问题,但我一直想知道

结束未清理的线程。我使用thread.start启动它们

但没有结束它们。我被告知VB会清理它们。


从2003年到2005年没有变化的一件事是

Thread.ApartmentState = ApartmentState.STA。 2005年说它已经过时但是

程序运行所以我忽略了它的警告。这会导致问题吗?


有什么想法吗?
>I have a 2005 TCP/IP server that creates a new thread to handle each
incoming TCP/IP request. Once the request has been answered by the thread
the TCP/IP socket is disconnected and the sub/thread ends. This program
originally written in 2003 and I rewrote it in 2005 earlier this year. I
don''t know how long this has been going on but we just noticed today that
the program was using over a gig of virtual memory. Real memory was quite
low. The program had been running about 2 weeks. Shutting it down and
restarting it dropped the virtual memory to almost nothing.

I don''t know what causes this problem but I''ve always wondered about the
threads that end not being cleaned up. I use thread.start to start them
but nothing to end them. I''ve been told VB will clean these up.

One thing that didn''t change over from 2003 to 2005 was
Thread.ApartmentState = ApartmentState.STA. 2005 says it obsolete but the
program runs so I ignored it''s warning. Could this be causing a problem?

Any ideas?



嗨cj,

此问题可能是由创建新线程来处理每个传入的/>
请求,因为一个新线程将消耗1MB虚拟内存。您可以考虑使用线程池重新设计您的应用程序。
我想在这里提供以下文章供您参考:

在.NET Framework中编写线程池
http://msdn2.microsoft.com/en-us/library/ms973903.aspx

托管线程池
http://msdn2.microsoft.com/en-us/library/0ka9477y.aspx


希望这会有所帮助。如果您有任何其他

的问题或疑虑,请随时告诉我们。

祝您有个愉快的一天!


Best问候,

Charles Wang

Microsoft在线社区支持

================== ================================ ===

通过电子邮件收到我的帖子通知?请参阅:
http:// msdn。 microsoft.com/subscripti...ult.aspx#notif

ications


如果您使用的是Outlook Express,请确保清除复选框

工具/选项/读取:一次获取300个标题及时看到您的回复。

注意:MSDN托管新闻组支持服务是针对非紧急问题的。

来自社区或Microsoft支持的初始响应
工程师可在1个工作日内完成。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx

======================================== ========== ====

在回复帖子时,请回复群组通过

您的新闻阅读器,以便其他人可以从这个问题中学习并从中受益。

============ ====================================== ====

该帖子是按原样提供的。没有保证,也没有授予任何权利。

================================= ================= ====

Hi cj,
This issue might be caused by creating a new thread to handle each incoming
request since one new thread will consume 1MB virtual memory. You may
consider to use Thread Pool to redesign your application. I would like to
provide the following articles here for your reference:
Programming the Thread Pool in the .NET Framework
http://msdn2.microsoft.com/en-us/library/ms973903.aspx
The Managed Thread Pool
http://msdn2.microsoft.com/en-us/library/0ka9477y.aspx

Hope this helps. Please feel free to let us know if you have any other
questions or concerns.
Have a good day!

Best regards,
Charles Wang
Microsoft Online Community Support
================================================== ===
Get notification to my posts through email? Please refer to:
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications

If you are using Outlook Express, please make sure you clear the check box
"Tools/Options/Read: Get 300 headers at a time" to see your reply promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
================================================== ====
When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from this issue.
================================================== ====
This posting is provided "AS IS" with no warranties, and confers no rights.
================================================== ====


这篇关于多线程tcp / ip服务器大页面文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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