开发者

WCF Service Hosted in Windows Service running 10x slower than console app

开发者 https://www.devze.com 2023-02-15 14:54 出处:网络
I have a C# library that does some file processing. I created a console and desktop application that uses the library and processes a 256mb file in about 1min. I then created a WCF service hosted in a

I have a C# library that does some file processing. I created a console and desktop application that uses the library and processes a 256mb file in about 1min. I then created a WCF service hosted in a windo开发者_运维问答ws service which uses the same file processing library yet takes 10x longer to process the same 256mb file when called from a website. The windows service is running under a domain account with administrator privileges.

The overhead in calling the WCF service is very fast yet the LoadFile method takes much much longer. I tried increasing the process priority during startup via

Process.GetCurrentProcess ().PriorityClass = ProcessPriorityClass.High;

to no avail. I've run this service on a Win7 64bit desktop system (6gb), 2003 XP 32bit server (4gb) and 2008 R2 32bit server (4bg) all with similar results. The console and desktop apps each process the file in about 1min on the above system. The process does not appear to be memory constrained and entering swapville.

Are windows services somehow process constrained? Would I get better results running the WCF service under IIS?

EDIT: I tried calling the library directory from the website and that too takes 10x longer than the console or desktop application.

UPDATE: Turns out it was Log4PostSharp. The console and desktop apps didn't have any traces of log4net in the configuration files yet the website and windows service did. There was a log4net TraceAppender silently eating up precious CPU cycles.


I cannot think why the behaviour you describe is happening - it does seem very strange. Since you are processing a relatively large file in memory though, the garbage collector may be affecting it. You could try changing the mode the garbage collector runs in to see if it has any effect.

The garbage collector has three modes - workstation, server and concurrent. Each one behaves in a different way and is optimised for different types of applications. Workstation mode is the default mode, and is what all processes run using unless configured to use something else. More info about the modes can be found here.

Try explicitly setting the garbage collector to use server mode (it will only have an effect on a multi-processor machine though). To do this, put the following in your app.config file:

<configuration>
    <runtime>
        <gcServer enabled="true" />
    </runtime>
</configuration>
0

精彩评论

暂无评论...
验证码 换一张
取 消