Multi-Threaded applicaiton has poor performace on a machine? - c#

I have created a multi-threaded application that runs fine on every system except for one. The system is a windows 7 home edition setup. The 2 systems is running fine on are windows 7 Ultimate. Instead of each thread running independently, they seem to run in tandem. Also it runs really slow. It is really strange. I think the system is a quad core system and not sure if that has anything to do with it. I know I don’t have any code up here, but I was hoping you all might have some ideas.
Update:
Well, it turned out someone had removed the indexes out of my database. It seemed like the applicaiton was hanging, but it really was having trouble updating the records becuase the PK was removed. Thank all for your thoughts.

I'm pretty sure Windows 7 home basic has a built in limit of a single processor.
Yup:
http://en.wikipedia.org/wiki/Windows_7_editions

Was an issue with indexes being removed fromt he database.

Related

Entity Framework startup slow on everyone's computer but mine

We started developing an application in C# recently and decided to try Entity Framework 6.1.3 with a code-first approach to handle persistence. The data is being stored in a SQL Server Express 2012 instance which is running on a local server. The application is still very small. Currently we are only persisting two POCOs and have two tables in the database: one with 5 fields (about 10 rows of data), and one with 4 fields (2 rows).
We are experiencing a 3 second delay when Entity Framework processes the first query with subsequent queries being extremely quick. After some searching we found that this is normal for Entity Framework so, although it seemed excessive for such a small database, we've been coping with it.
After doing some work today, none of which was specifically related to persistence, suddenly I found that the first query was only taking a quarter of a second to run. I couldn't see anything obvious in the changes I'd made so I uploaded them to source control and asked my colleague to download everything. When he builds and runs it on his computer, it still takes 3 seconds for the first query. I've compiled the application, tried it on two test computers and they experience the initial 3 second delay.
There seems to be no correlation between the problem and the computers/operating systems. My computer is running Windows 7 SP1 x64. My colleague's development computer is running Windows 10 x64. The other two test computers are running Windows 7 SP1 x86. They are all a similar specification (Core i5, 4GB/8GB RAM).
In my research of the delay I found that there are several things you can do to improve performance (pre-generating views etc) and I have done none of this. I haven't installed anything or made any changes to my system, although I suppose it's possible an update was installed in the background. Nothing has changed on the database server or in the database itself or in the POCOs. We are all connecting to the same database on the same server.
This raises a few obviously related questions. If it's possible for it to start up in a quarter of a second, why has it been taking 3 seconds up until now? What happened on my computer to suddenly improve performance and how can I replicate this on the other computers that are still slow?
Can anyone offer any advice please?
EDIT
I turned on logging in Entity Framework to see what queries were being run and how long they were taking. Before the first and, for testing purposes, only query is run, EF runs 3 queries to do with migration. The query generated to retrieve my data follows that and is as follows:
SELECT
[Extent1].[AccountStatusId] AS [AccountStatusId],
[Extent1].[Name] AS [Name],
[Extent1].[Description] AS [Description],
[Extent1].[SortOrder] AS [SortOrder]
FROM [dbo].[AccountStatus] AS [Extent1]
-- Executing at 28/01/2016 20:55:16 +00:00
-- Completed in 0 ms with result: SqlDataReader
As you can see it runs really quickly which is hardly surprising considering there are only 2 records in that table. The 3 migration queries and my query take no longer than 5ms to run in total on both my computer and my colleague's computer.
Copying that query in to SSMS and running it from various other machines produces the same result. It's that fast it doesn't register a time taken. It certainly doesn't look like the query causes the delay.
EDIT 2: Screenshots of diagnostic tools
In order to give a good comparison I've altered the code so that the query runs at application start. I've added a red arrow to indicate the point at which the form appears. I hadn't noticed before but when my colleague runs the application the first time after starting Visual Studio, it's about a second quicker. All subsequent times are slower.
1) Colleague's computer - first run after loading Visual Studio
2) Colleague's computer - all subsequent runs
3) My computer - all runs
So every time my colleague runs the application (apart from the first time) there is a second's pause in addition to the usual delay. The first run immediately after starting Visual Studio seems to eliminate this second's pause but it's still no where near the speed on my computer.
Incidentally, there is a normal delay of around a quarter of a second caused by the application starting. If I change the application to require a button click for the first query, the second's pause and usual 2 second delay happen only after the button is clicked.
Another thing of note is the amount of memory the application uses. Most of the time on my computer it will use around 40MB but on the other computer it never seems to use more than 35MB. Could there be some kind of memory optimisation going on that is slowing things down for the other computer? Maybe my computer is loading some additional/cached information in to memory that the others are having to generate. If this is possible, any thoughts on where I might look for this?
EDIT 3
I've been holding off making changes to the model and database because I was worried the delay would come back and I'd not have anything to test against. Just wanted to add that after exhausting all other possibilities, I've tried modifying a POCO and the database and it's still quick on my computer but slow on others.
I've altered the title of this question to more accurately reflect the problem I'm trying to solve.
Query plans in SQL Server can change over time. It may be that your machine has cached a good query plan, while your co workers machine has not. In other words, it may have nothing to do with EF. You could potentially confirm or deny this theory by running the same query by hand in management studio.
In order to tackle performance problems related to EF generated queries, I advice you to use Profiler or an alternative (as Express Editions do not have it) to see how much of your time is actually consumed running the query.
If most of your time is used for running the query, as already suggested by jackmott, you can run it in SSMS by toggling Actual Execution Plan to see the generated plan in each situation.
If time is spent on something else (some C# warming up or something similar), Visual Studio 2015 has builtin performance analysis that can be used to see where it is spending that time.

Downloading and executing EXE's with Windows Universal

Im porting an app from XPe to WinRT, which runs on 1000's of machines remotely, it downloads a few other critical exe's and runs them, occasionally updating them etc.
I'm a bit concerned that unlike in XPe this may somehow be a big no-no for security reasons. No I don't want to use any kind of generic update process.
Can anyone comment on the feasibility of this? Im a bit afraid I'll hit a brick wall from security point of view. As so far WinRT seems very restrictive by comparison, bit like Android where everything is an app etc..
(PS. this is a corporate project, the machines are embedded and completely owned by us.)

Ways of isolating cause of unresponsive Winforms GUI

I have a large-ish Winforms application written in C# which is periodically unresponsive. The issue seems to occur once the application has been use for an hour or so. Exact timings are difficult to gather as users often go off to work on something selse, get back to it and find it has become unresponsive.
I think a memory leak can be ruled out as I'm not seeing excessive memory usage (I've asked users to send a screenshot of the task manager and memory usagage is the same as I would see when the application is runnning normally)
Similarly, CPU usage is normal (single digit %)
As I've so far been unable to recreate the issue on mydevelopment PC I am planning on sitting next to one of the affected users and mirror every action the user performs in order to recreate this. (I'll be setting up a laptop to RDP in to my main PC)
Recreating the issue is one thing, but I'll need to find out what is actually going on in the application.
Could anyone tell me if running in debug mode (through visual studio) will be sufficient or will I need to do something different?
I've searched through a few posts and I've seen mention of profiling software, however I'm not sure if this would only help with general performance issues or memory management issues.
Alternatively, if anyone has come across similar freezing issues then do you have any suggestions of the kind of causes for this?
Some technical details: Aplication is C#, compiled against .NET 3.5, winforms GUI. There are a few external libraries (most significant is ComponentFactory Krypton Suite). Data access is to a Microsoft SQL Server 2005 database. The solution contains 39 projects, I'm not sure if that might have something to do with it?
Any suggestions/pointers would be greatly appreciated.
The application is working much more reliably now, freezing issues still occur on occasion but nowhere near as often as before.
The issue appears to be related to the endpoint security (in this case, Cisco Security Agent) present in the environment I'm working in, application has been whitelisted and has has significantly rediced the instances of application hangs. The development system I work on does not have this endpoint security present, so it didn't show up in early stages of testing.
Thanks for all your feedback, I think there are still threading and garbage collection issues that need cleaning up, hopefully this should sort out the last few issues.

.NET Applications performance problem on Windows 2003

We have a 2 x Quad Core Xeon server with 8GB of RAM and Windows Server 2003 Enterprise installed on it. We installed our application server which is based on .NET Framework 3.5 on it. The server uses SQL Server 2005 as its database server.
When we installed the application server, it used to have ultra fast performance and everything was fine. Once we joined it into our domain, its performance decreased dramatically. For example a task that took 1 sec to complete, now takes about 30 sec. This is very strange since only .NET based applications' performance got this performance hit but the other applications still run at their normal speed.
Does anyone have any idea about why is this happening? Any help or suggestion is much appreciated.
Unfortunately, more is probably needed to answer your question. There are a host of possible reasons why this is occurring, and most of them involve your code.
Based on the symptom that you joined the domain and then things started causing trouble, I'd say you've got a lot of networking that you're doing that previously was able to be done locally on your machine and the latency is now actually causing trouble.
But that's a wild guess based on not nearly enough information.
I'd suggest you profile your code. Find out where the majority of your time is spent during execution and then post the code or a sanitized version of it here so we can help you optimize it.
I did find the answer to my question so i thought it might be good to share it here. The CLR want generate publisher evidence for assemblies with authenticode signature when it tries to load the assemblies. In our case CLR was trying to connect to clr.microsoft.com but our server's internet access was blocked so it caused huge delay whenever the application server tries to load a new assembly.
The following post describes how you can disable this feature:
Bypassing the Authenticode Signature Check on Startup
I'm going to make a guess here and think that you're talking about a web application. If this is correct, you might want to take a look at the application pools you have setup on the webserver. Your application might be getting confused about which pool to set itself in when it starts running.
Another thing to check might be your data connections and make sure that you're closing everything that's been opened.
The last thing, like Randolpho said, you're just really going to have to follow your code execution with some kind of profiler and see where things are getting tied up.
Good luck!

Visual Studio 2008 crashes horribly

This has happened to me 3 times now, and I am wondering if anyone is having the same problem. I am running Visual Studio 2008 SP1, and hitting SQL Server 2005 developer edition.
For testing, I use the Server Explorer to browse a database I have already created. For testing I will insert data by hand (right click table -> show table data).
I can do this for a week without problems, but sometimes my computer will crash when the stars are aligned. It doesn't hang, it doesn't blue screen, I see the bios boot screen .2 seconds after I enter some value in a new row that hasn't been saved yet. I have never seen a crash like this, where it reboots instantly. I think it may happen when I enter something that violates a database constraint, but I am not sure yet (need a few more crashes to pinpoint it).
Anyone have the same problem? Know of a solution? Too bad VS wasn't written with managed code, eh? :)
UPDATE: I can reproduce it by inserting a duplicate primary key, clicking off the row, clicking OK on the database error notification, then trying to update the primary key again. I agree - it definitely sounds like a hardware or driver issue, but am not really sure how to solve this since this has only happened when doing this 1 particular thing in VS. I am not overclocking either - I am running a normal (single core) 3 Ghz Dell.
Just so you know, when your computer just snaps right back to the BIOS boot screen with no blue screen or other crash data, this is called a "triple fault" Basically, there was an exception (on a hardware level) whose exception handler triggered an exception whose exception handler triggered an exception. This is almost always a hardware issue since operating systems tend to be VERY careful in the double fault handler not to trigger an exception.
Needless to say, it could be a software problem, but I would check your RAM, CPU and motherboard for potential issues. I had a dell which was doing this fairly randomly with Vista and a new mobo/CPU from dell solved it perfectly.
EDIT: just to note, it can be very hard to convince dell that it is indeed a hardware issue, but stick with it and eventually they'll cave and fix it for you.
Test your memory, it's the most likely cause of your reboots.
Visual Studio 2008 is just an application, no application should be able to cause your machine to reboot like that.
What can cause your machine to reboot like that is drivers and hardware...
Not to just jump on the bandwagon, but in the past 15 years every instance of this type of situation I have come across has been caused by hardware failure.
Good news is at least that is often eaiser to fix.
Are you able to swap the entire box out, even if only for a few weeks? Often I really don't care what piece failed -- I just yank the whole thing and sort it out later.
Joe
Are you overclocking the machine? Reboots like that are a sign that you have a bad overclock, ie. too high, bad voltage settings, bad memory timings.
I have the same apps running on my machine (on Vists32), and have not hit that problem.
Sounds suspiciously like a RAM problem to me, although I had a bad hard drive in a test server cause similar problems too, it even fried the motherboard, but most often this sort of thing is RAM.
I am not having a crash per se' but when I attept to run the group expert in crystal reports VS2008 hangs and can only be closed by using the task manager.
I'm experienced (read: old) enough to know that this SHOULD be a hardware issue. But...
Another developer and myself at the company where I'm currently working installed VS2008 last week, and now we're both seeing this problem. Every now and then, about once a day, when using the IDE the machine will reset as if someone had pushed the reset switch. (The reset button is not expoesed on these machines.)
We have identical hardware (Dell Optiplex GX620, 2GB RAM, WinXPsp2) as do the other ~20 developers here. The other staff use VS2005. We are the only ones having the problem. The machines are stock (it's a stodgy corporate environment) and well-maintained.
So, while this shouldn't be related to VS, it's an awful lot of circumstantial evidence.
For what it's worth, I run VS2008 at home with no issues.
Do use Symantec anti-virus? I had a situation with a new machine where just pressing the ALT-TAB combination would cause my machine to spontaneously reboot about 50% of the time. When Windows restarted it said I had experienced an issue related to a driver.
I mentioned it to our IT guy and he said that it was Symantec and that he had an update that would fix it. Needless to say it really felt like a hardware issue to me, so I was more than skeptical. But he updated my Symantec install and the issue went away!
Try disabling your anti-virus to see if it goes away for a while. And if it does, see if there is an update from your anti-virus vendor
To check the status of your RAM or Hard drives use UBCD (link)
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=329016
http://social.msdn.microsoft.com/forums/en-US/winforms/thread/879ab314-07b2-484e-989c-5661e5bc234a/
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=331888
I had the same problem early 2008. I believe it was a video driver problem. That a data table in a window could crash windows this way is amazing. There have been so many reports of this that I don't think it's hardware related. Microsoft won't accept it as a bug since they can't reproduce it. Still a bug though.
In house visual Studio 2008 debugger was crashing. Symantec was the culprit. Removal of Symantec services resolved that problem for this system. Thought this might help other developers that see strange crashes in VS2008 try disabling Symantec AV and stopping services on boot.

Categories