Execution of same code taking longer in IIS than in desktop application - c#

I have a module that performs multiple SQL Server database operations.
When I execute this module in IIS (inside RESTful Service), the execution of this module takes about twice the time it takes while executing inside desktop application in the same computer.
In both, IIS and Desktop applications, software factors such as number of database operations, data impacted, etc are same.
I tried changing various properties in application pool, but I could not lower the running time in IIS to match to that in desktop application.
Are there any settings in IIS which help lowering the running time of the module?
Is running in IIS is supposed to be slower than in normal desktop application? Why?

Related

Log into remote computer using C#

I'm working on an application to start up the various servers and workstations in a system from one central server. As part of this, I need to log in to several workstations (currently running Windows 7) so that their startup applications can load.
I have tried running the startup applications remotely (using both a WMI approach and a scheduled tasks approach), but that has not resulted in the application fully initializing.
Does anyone have any suggestions on other angles I could try? Note that I cannot use PSExec on these systems.
UPDATE: To isolate the specific problem, is there a way to non-interactively remotely log in to a server as a specified user so that its startup applications execute as if the user just logged in on the workstation manually?

Restart crashed executable when multiple instance of the same is running

I have developed an application (.NET C#) for document processing and below is the application's architecture:
My application uses SQL Server, WCF Windows Service, Indexer and Processing.exe. When user start processing documents, Service launches Processing.exe with specific parameters like which documents to process and which user has requested processing. There are multiple users using application so Service can start Processing.exe multiple times as per requirements.
Now, one of Processing.exe crashes without completing the task! So my question is... How can we restart that one particular Processing.exe when it crashes? Or can we get notification that process is crashed? In short, How can we manage this?

IIS high process load

I have an IIS server version 8.5. I have web site and a number of web-services hosted on this web site. A number of windows services and desktop apps are working this with IIS instance. And everything is ok for some time. But some time later IIS begin to use 100% of cpu resources. I can suppose that my code is the probem, but firstly i'm doing next steps:
I'm switching off all windows services and desktop apps.
Switching off w3wp process from processes.
Restrating several times app pool, iis and site.
But after i'm startig again iis, pool and site and nothing else (nothing is using iis) i can see that iis worker process using about 20% of cpu resources. And the situation above can be repeated again after some time. It means that the problem can't be in the my code.
What can be the problem of the iis high-load then it just started and then it uses 100% of cpu?
It happens, we've all struggled with high CPU in a worker process before. It in almost all cases it is the code.
If you're threading (That's probably your answer right their)
But here's what you need to do.
Right click on the process consuming the CPU and click "Dump Process", this will create a debug file.
Then use debug diagnostic tool from Microsoft and open the file, it has a wealth of information in it. It's your starting point. Unless you're willing to share the code.

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

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 windows 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>

Global.asax and web application lifetime

Question: When a webapplication gets started, it executes Application_Start in global.asax.
Now, a web application gets started as soon as the first request for a page in that application reaches the server.
But my question is: how long will the application run until the application is stopped.
I mean when after the first page request, there's no traffic on the server.
I need to know because I intend to start a server that listens on a tcp port in global.asax.
And when the application stops, the server ceases to listen to its port.
It depends on your IIS settings. Your application will run in an application pool, which takes a bunch of settings defining the behaviour of this pool.
The thing you're looking for are recycling settings. In IIS 7, you can access these easily from the management console. Go to Application Pools, right click on the application pool your app runs in (if you don't know which one that is, then it's probably the DefaultAppPool) and select recycling.
Here you'll find the options you have to control the recycling behaviour of your app pool, which in turn controls when your app 'resets'.
in a word (well 2) - shared hosting.
on shared hosting beware, (godaddy/webhost4life etc) this timeout could well be less, plus you don't have option to configure that on these hosting environments. i've had cases where the app pool is recycled after 5 mins at certain peek times, so you might have to investigate 'wakeup' routines to poke your app to keep in in the memory. i do this for a few shared hosting apps to great effect using pingalive.com.
hope this helps, even if in an abstract way.
jim

Categories

Resources