By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,490 Members | 1,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,490 IT Pros & Developers. It's quick & easy.

Reducing memory usage in a windows service

P: n/a
I've written a basic windows service to provide some helper xml functions for
my web methods and even thou the service is only about 1k lines long with 1
timer, its mem usage is 10m and its vm mem usage is 14! The same code written
as a program that requires you to click on the menu options to fire off the
events takes up 4/9mb.

I've seen examples where calling SetProcessWorkingSetSize(hWnd, -1, -1); does
the same thing as minimizing a program to reduce the memory use but I can't
minimize a service and calling the setprocess function lowers the memory usage
by 0 bytes.

Are there any other ways to lower the memory usage? Even after some 40+ hours
of running the service was still consuming 10mb of ram. I just dont see how 1
timer and some xml calls with file operations takes up 10mb.
Nov 16 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Has it been compiled as a Release versus the default Debug?

Patrick Altman
"Greg Merideth" <gm**************@this.forwardtechnology.net> wrote in
message news:Ed********************@comcast.com...
I've written a basic windows service to provide some helper xml functions for my web methods and even thou the service is only about 1k lines long with 1 timer, its mem usage is 10m and its vm mem usage is 14! The same code written as a program that requires you to click on the menu options to fire off the events takes up 4/9mb.

I've seen examples where calling SetProcessWorkingSetSize(hWnd, -1, -1); does the same thing as minimizing a program to reduce the memory use but I can't minimize a service and calling the setprocess function lowers the memory usage by 0 bytes.

Are there any other ways to lower the memory usage? Even after some 40+ hours of running the service was still consuming 10mb of ram. I just dont see how 1 timer and some xml calls with file operations takes up 10mb.

Nov 16 '05 #2

P: n/a
Greg,

You should expect this. The 10 MB is for the runtime, mainly for the
memory management. This is just the price you pay for it.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Greg Merideth" <gm**************@this.forwardtechnology.net> wrote in
message news:Ed********************@comcast.com...
I've written a basic windows service to provide some helper xml functions
for my web methods and even thou the service is only about 1k lines long
with 1 timer, its mem usage is 10m and its vm mem usage is 14! The same
code written as a program that requires you to click on the menu options
to fire off the events takes up 4/9mb.

I've seen examples where calling SetProcessWorkingSetSize(hWnd, -1, -1);
does the same thing as minimizing a program to reduce the memory use but I
can't minimize a service and calling the setprocess function lowers the
memory usage by 0 bytes.

Are there any other ways to lower the memory usage? Even after some 40+
hours of running the service was still consuming 10mb of ram. I just dont
see how 1 timer and some xml calls with file operations takes up 10mb.

Nov 16 '05 #3

P: n/a
Greg Merideth wrote:
I've written a basic windows service to provide some helper xml
functions for my web methods and even thou the service is only about
1k lines long with 1 timer, its mem usage is 10m and its vm mem usage
is 14! The same code written as a program that requires you to click
on the menu options to fire off the events takes up 4/9mb.
See: Analyzing Common CLR Performance Problems
http://blogs.msdn.com/akhune/archive...11/153734.aspx

In short: The GC always allocated at al lot of memory in advance...
I've seen examples where calling SetProcessWorkingSetSize(hWnd, -1,
-1); does the same thing as minimizing a program to reduce the memory
use but I can't minimize a service and calling the setprocess function
lowers the memory usage by 0 bytes.
With 'SetProcessWorkingSetSize' you do not minimize the memory!!! you only
minimize the working set (and thus leads to more page-faults).

Are there any other ways to lower the memory usage? Even after some
40+ hours of running the service was still consuming 10mb of ram. I
just dont see how 1 timer and some xml calls with file operations
takes up 10mb.


To reduce the memory usage dramatically write your code in unmanaged C++.

I think with using the server-GC you can also reduce some preallocated
memory (but I forgott the link...)

Greetings
Jochen
Nov 16 '05 #4

P: n/a
Hello Patrick,
Has it been compiled as a Release versus the default Debug?


Would this make a difference !?
The Debug version only has the "DebuggableAttribute" set to (true, true).

This only disables the optimizer and does not track some JIT infos...

Greetings
Jochen
Nov 16 '05 #5

P: n/a
Hi,

In my experience I think that around 8-10 is the lower memory consuption of
any .net program, Do you really find that big?
Doom 3 consume around 500 MB :)

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Greg Merideth" <gm**************@this.forwardtechnology.net> wrote in
message news:Ed********************@comcast.com...
I've written a basic windows service to provide some helper xml functions for my web methods and even thou the service is only about 1k lines long with 1 timer, its mem usage is 10m and its vm mem usage is 14! The same code written as a program that requires you to click on the menu options to fire off the events takes up 4/9mb.

I've seen examples where calling SetProcessWorkingSetSize(hWnd, -1, -1); does the same thing as minimizing a program to reduce the memory use but I can't minimize a service and calling the setprocess function lowers the memory usage by 0 bytes.

Are there any other ways to lower the memory usage? Even after some 40+ hours of running the service was still consuming 10mb of ram. I just dont see how 1 timer and some xml calls with file operations takes up 10mb.

Nov 16 '05 #6

P: n/a
Its in release mode but after reading the other messages I'll look into moving
the entire set of helper functions into c++ to lower the memory consumption.

I understand that the memory management is part of it so mabye the .net c# way
isn't a good way to go, even with the ease of it, as a process to create
services. Mabye with visual studio 2010 it might be less memory intensive :)

Now to go mess up my machine with c++!

Patrick Altman wrote:
Has it been compiled as a Release versus the default Debug?

Patrick Altman
"Greg Merideth" <gm**************@this.forwardtechnology.net> wrote in
message news:Ed********************@comcast.com...
I've written a basic windows service to provide some helper xml functions


for
my web methods and even thou the service is only about 1k lines long with


1
timer, its mem usage is 10m and its vm mem usage is 14! The same code


written
as a program that requires you to click on the menu options to fire off


the
events takes up 4/9mb.

I've seen examples where calling SetProcessWorkingSetSize(hWnd, -1, -1);


does
the same thing as minimizing a program to reduce the memory use but I


can't
minimize a service and calling the setprocess function lowers the memory


usage
by 0 bytes.

Are there any other ways to lower the memory usage? Even after some 40+


hours
of running the service was still consuming 10mb of ram. I just dont see


how 1
timer and some xml calls with file operations takes up 10mb.


Nov 16 '05 #7

P: n/a
Reducing the working set by calling SetProcessWorkingSetSize, only works for
UI style applications and is considered bad practice.
Not sure what you mean with "set of helper functions into c++ ", but if you
mean by that that you are reimplementing part of your service in C++ and
keep another part managed, then this won't reduce the working set.
Also I'm not clear on what memory counter you are looking at? If it's the
"working set" you should know that a large amount of this one consists of
shared/shareable pages.
Willy.
"Greg Merideth" <gm**************@this.forwardtechnology.net> wrote in
message news:Jd********************@comcast.com...
Its in release mode but after reading the other messages I'll look into
moving the entire set of helper functions into c++ to lower the memory
consumption.

I understand that the memory management is part of it so mabye the .net c#
way isn't a good way to go, even with the ease of it, as a process to
create services. Mabye with visual studio 2010 it might be less memory
intensive :)

Now to go mess up my machine with c++!

Patrick Altman wrote:
Has it been compiled as a Release versus the default Debug?

Patrick Altman
"Greg Merideth" <gm**************@this.forwardtechnology.net> wrote in
message news:Ed********************@comcast.com...
I've written a basic windows service to provide some helper xml functions


for
my web methods and even thou the service is only about 1k lines long with


1
timer, its mem usage is 10m and its vm mem usage is 14! The same code


written
as a program that requires you to click on the menu options to fire off


the
events takes up 4/9mb.

I've seen examples where calling SetProcessWorkingSetSize(hWnd, -1, -1);


does
the same thing as minimizing a program to reduce the memory use but I


can't
minimize a service and calling the setprocess function lowers the memory


usage
by 0 bytes.

Are there any other ways to lower the memory usage? Even after some 40+


hours
of running the service was still consuming 10mb of ram. I just dont see


how 1
timer and some xml calls with file operations takes up 10mb.



Nov 16 '05 #8

P: n/a
..NET programs don't use all the memory they allocate. If you fill up your
ram, the memory management of .NET applications will change to a more a more
agressive mode. For exemple I have a "small" winform application that takes
20Mb at launch. If I fill up my ram (by launching 3 virtual machines, damn
1Gb is hard to fill up!) it's memory usage goes down to 2Mb.

Of course, going C++ is going to save you even more than that.

Etienne Boucher
Nov 16 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.