PC Review


Reply
Thread Tools Rate Thread

.Net 2.0 memory usage

 
 
Joe K
Guest
Posts: n/a
 
      14th Feb 2007
I ported a .Net service from 1.1 to 2.0. In .Net 1.1, the total private
bytes for this service ran around 40MB. In .Net 2.0, the same service has
total private bytes of around 140MB. I then ran our service under a memory
debugger, and we have a total of 34 MB allocated on the heap.

Anyone have any ideas as to where the extra 100MB is going in .Net 2.0?

Joe


 
Reply With Quote
 
 
 
 
Joe K
Guest
Posts: n/a
 
      14th Feb 2007
So check this out:
- .Net memory # Bytes in all Heaps = 1.8 MB
- .Net memory # Total committed bytes = 3.3 MB
- .Net memory # Total reserved bytes = 33.9 MB
- Private bytes = 139.6 MB

Huh? This make any sense to anyone?


 
Reply With Quote
 
ForrestPhoto@gmail.com
Guest
Posts: n/a
 
      15th Feb 2007
> Huh? This make any sense to anyone?

No. What does your service do?

 
Reply With Quote
 
Joe K
Guest
Posts: n/a
 
      15th Feb 2007
I have a little more information. The difference appears to be related to
System.Threading.Thread. If I build a standalone .Net service in .Net 2.0
that starts 100 threads, I will see ~110 MB of memory allocated in private
bytes to this process. The same code on .Net 1.1 results in 7 MB of memory
in private bytes.

If anyone can explain this, I am very interested in understanding this.

Thanks.

Joe


 
Reply With Quote
 
Henning Krause [MVP - Exchange]
Guest
Posts: n/a
 
      15th Feb 2007
Hello,

usually, every thread has a stack size of 1 MB... but AFAIK, that has not
changed from 1.1 to 2.0. So I would guess, the .NET 2.0 behavior is
correct. I'm not sure why a .NET 1.1 software would behave other.

Albeit from this: Why are you using 100 threads? Seem very much to me...
either, most of your threads wait most of the time, or you'll have many
thread context switches...

Best regards,
Henning Krause


"Joe K" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a little more information. The difference appears to be related to
> System.Threading.Thread. If I build a standalone .Net service in .Net 2.0
> that starts 100 threads, I will see ~110 MB of memory allocated in private
> bytes to this process. The same code on .Net 1.1 results in 7 MB of
> memory
> in private bytes.
>
> If anyone can explain this, I am very interested in understanding this.
>
> Thanks.
>
> Joe
>
>


 
Reply With Quote
 
Joe K
Guest
Posts: n/a
 
      15th Feb 2007
My theory is that the .Net 2.0 behavior is correct too - I just can't
explain what I see in .Net 1.1

Is it possible that .Net 1.1 used the Win32 thread pool in some way,
resulting in the memory allocated for a threads to be counted as shared
memory, and thus not being counted in private bytes?

I used 100 as an example. Our thread pool shrinks/grows based on demand.

Joe


 
Reply With Quote
 
Henning Krause [MVP - Exchange]
Guest
Posts: n/a
 
      15th Feb 2007
Hello,

the .NET ThreadPool is built ontop on the Win32 threadpool in both versions.

But if you create 100 threads yourself, the ThreadPool is not used...

Best regards,
Henning Krause

"Joe K" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> My theory is that the .Net 2.0 behavior is correct too - I just can't
> explain what I see in .Net 1.1
>
> Is it possible that .Net 1.1 used the Win32 thread pool in some way,
> resulting in the memory allocated for a threads to be counted as shared
> memory, and thus not being counted in private bytes?
>
> I used 100 as an example. Our thread pool shrinks/grows based on demand.
>
> Joe
>
>


 
Reply With Quote
 
Joe K
Guest
Posts: n/a
 
      16th Feb 2007
Okay, then I can't explain it. Go ahead and try it though. The below code
in .Net 1.1 reports 7MB for private bytes, but 111MB in 2.0.

namespace TestService
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}

protected override void OnStart(string[] args)
{
for (int i = 0; i < 100; i++)
{
Thread thread = new Thread(Service1.Run);
thread.Start();
}
}

protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to
stop your service.
}

protected static void Run()
{
while (true)
{
Thread.Sleep(1000*10);
}
}
}
}




 
Reply With Quote
 
Chris Mullins [MVP]
Guest
Posts: n/a
 
      16th Feb 2007
If nothing else, you're creating 100 threads. Each thread requires 1 Meg of
stack space from your Working Set. That's 100 Megs already.

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

"Joe K" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Okay, then I can't explain it. Go ahead and try it though. The below
> code
> in .Net 1.1 reports 7MB for private bytes, but 111MB in 2.0.
>
> namespace TestService
> {
> public partial class Service1 : ServiceBase
> {
> public Service1()
> {
> InitializeComponent();
> }
>
> protected override void OnStart(string[] args)
> {
> for (int i = 0; i < 100; i++)
> {
> Thread thread = new Thread(Service1.Run);
> thread.Start();
> }
> }
>
> protected override void OnStop()
> {
> // TODO: Add code here to perform any tear-down necessary to
> stop your service.
> }
>
> protected static void Run()
> {
> while (true)
> {
> Thread.Sleep(1000*10);
> }
> }
> }
> }
>
>
>
>



 
Reply With Quote
 
Joe K
Guest
Posts: n/a
 
      16th Feb 2007
Create 10, 20 or 100 threads in your test, and the result will still be the
same: thread memory is not counted in private bytes in 1.1, but is in 2.0.
I'm just wondering why? Not sure I understand the fixation on the # of
threads - that has nothing to do with my question.

Joe


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
My available memory is down to very little, yet my PF Usage is 8 gigabytes (about how much memory is on the box), sql server keeps having memory issues yet the sqlservr.exe is using hardly any memory.. how to fix this? is there some way to limit how Daniel Microsoft Windows 2000 Security 1 30th Aug 2007 08:38 AM
My available memory is down to very little, yet my PF Usage is 8 gigabytes (about how much memory is on the box), sql server keeps having memory issues yet the sqlservr.exe is using hardly any memory.. how to fix this? is there some way to limit how Daniel Microsoft Windows 2000 1 30th Aug 2007 02:22 AM
My available memory is down to very little, yet my PF Usage is 8 gigabytes (about how much memory is on the box), sql server keeps having memory issues yet the sqlservr.exe is using hardly any memory.. how to fix this? is there some way to limit how Daniel Microsoft Windows 2000 Networking 0 28th Aug 2007 01:38 AM
My available memory is down to very little, yet my PF Usage is 8 gigabytes (about how much memory is on the box), sql server keeps having memory issues yet the sqlservr.exe is using hardly any memory.. how to fix this? is there some way to limit how Daniel Microsoft Windows 2000 Advanced Server 0 28th Aug 2007 01:38 AM
Memory Usage and Page File Usage - Help! RH Microsoft C# .NET 4 26th May 2004 05:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:22 PM.