Re: C# System.String Memory Usage [TCP IP Connections]
- From: "Chris Mullins" <cmullins@xxxxxxxxx>
- Date: Mon, 18 Dec 2006 16:08:36 -0800
Hi Shawn,
If you're getting 5x the TCPIP performance by calling GC.Collect, you're
suffering very badly from heap fragmentation due to all the pinning that's
going on when you send/receive data.
GC.Collect isn't really the right answer there, although I understand how it
could look that way. What you really need is a buffer pool that's all
allocated together, and that you check byte[] buffers into and out of. This
way you don't allocate new byte[] each time you make a socket call - this
causes continual fragmentation, and you'll eventually run out of memory.
The problem is described in detail here:
https://blogs.msdn.com/yunjin/archive/2004/01/27/63642.aspx
A good pair of articles on the subject is here:
http://www.coversant.net/dotnetnuke/Default.aspx?tabid=88&EntryID=9
http://blogs.msdn.com/adarshk/archive/2005/08/20/454022.aspx
.... and the limits of how far you can go is talked about here:
http://www.coversant.net/Default.aspx?tabid=88&EntryID=10
In short (re: your original assertion) the only time you really want to call
"GC.Collect" is just before you're forced to grow your buffer pool. When you
do grow, you want to grow by a large amount (1k, 5k, 10k instances of
whatever your buffer size is) so that any holes in your heap are all close
together. This leverages the GC.Collect mostly to compact the heap, so that
your buffers are allocated as low as possible.
--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins
"Shawn B." <leabre@xxxxxxxx> wrote in message
news:u8HogwtIHHA.2456@xxxxxxxxxxxxxxxxxxxxxxx
calling GC.Collect is not a good solution. The .NET Framework calls those
methods when necessary, calling it manually will hardly do anything
useful (but some bad things...).
While this might be true (in general) I have a project that actually
improves scalability and performance by calling GC.Collect at the right
place. Without doing so, we can only get about N number of connections
(TCP/IP) on a single server. By doing so, we get about N*5 without a
single noticeable degradation of performance. There's also another place
where we have lots of string handling where placing a GC.Collect in the
right place drastically increases our perceivable performance.
But I agree with you, in general, there probly is a better way. But that
doesn't mean to rule out the possibility. Just because everyone says not
to, doesn't mean you shouldn't see for yourself whether doing so might
help your situation. Of course, this also assumes you understand more
about the GC/JIT/CLR internals than most others do. It also asummes you
are a master of profiling so you can determine whether it helps or not.
YMMV.
Thanks,
Shawn
.
- Follow-Ups:
- Re: C# System.String Memory Usage [TCP IP Connections]
- From: Shawn B.
- Re: C# System.String Memory Usage [TCP IP Connections]
- References:
- C# System.String Memory Usage
- From: mwhalber
- Re: C# System.String Memory Usage
- From: John Saunders
- Re: C# System.String Memory Usage
- From: Shawn B.
- Re: C# System.String Memory Usage
- From: Henning Krause [MVP - Exchange]
- Re: C# System.String Memory Usage
- From: Shawn B.
- C# System.String Memory Usage
- Prev by Date: Re: # of current physical Threads > 4 000 000 0000
- Next by Date: Re: C# System.String Memory Usage [TCP IP Connections]
- Previous by thread: Re: C# System.String Memory Usage
- Next by thread: Re: C# System.String Memory Usage [TCP IP Connections]
- Index(es):
Relevant Pages
|