Friday, February 24, 2012

Extreme slow SQL Server 2005 and high CPU usage - Casting of values

Hello sql and .net gurus :-)
I have a problem with my websitewww.eventguide.it. It's completly developed under .NET 2 and SQL Server 2005 Express. My problem is the folowing:
The server is a Intel 3Ghz HT processor with 1GB Ram. No other page on the running system is a CPU consuming site. We optimized the SQL statements, the code, the caching and many other parts of the website (pooling on SQL access), but the SQL Server uses about 50% to100% of the CPU and about 400MB RAM all the time. The whole site seems to be very, very slow. In fact there are many of SQL operations on every page request, but we cache a lot of them in different ways (page output caching, application caching). So I don't understand we have so much performance problems. Any suggestions for optimised code in general? I read nearly all of the MS .NET performance papers - but real world experience is the missing part :-)

It is better to cast the values of a SQL reader like this
Dim String1 as String = Ctype(DataReader.item(0), String)
Dim Integer1 as Intger = Ctype(DataReader.item(1), Integer)
or like this
Dim String1 as String = DataReader.item(0)
Dim Integer1 as Intger = DataReader.item(1)

Thanks a lot for your help!
FOX

I visited your site, and honestly I cant answer your question. Your SQL CPU usage seems way off, but the problem appears to be bandwidth entirely.

I pinged your site, and traced it with good solid pathways and quick responses. But going into the Foto's (photos) section resulted in pictures taking an extremely long time to load even after the page was rendered. Why type of up-pipe is that server pushing?

|||What do you mean with: "Why type of up-pipe is that server pushing?"|||

Sorry, horribly formed question:

How much bandwidth is available to the server over your connection, dedicated to "upload"?

|||The upload of the server is about 10Mbit - enough to deliver requests in a fast way.
Well - look now the speed of the entire site. Today I changed the SQL database index of a 2.000.000 rows counting table (counter for images and other things) and from one moment to another I reduced CPU usage dramatically! Now I try to optimize also other table indexes to increase the speed further.
Any suggestions to handle indexes in a good way?
Thanks for your time!!!|||I had close to the same issue. I added the port to the IP addresss in the connection string. Don't ask me why this fixed the issue, but it did. For the RAM issue, I also had this. The server would go up to almost 500-600MB of ram.. and it barely had anything in it!!

So I made a batch script to restart the server, and setup a windows scheduled task to run it every other day.

Here is my batch:
net stop MSSQLSERVER
echo y
net start MSSQLSERVER

net stop hmailserver
net start hmailserver

Basically, this will restart your SQL server. I do this at about 3AM. It keeps the server running top notch as far as I know.

I had to add hmailserver in there because if you don't restart it also, it for some reason will fail to verify accounts. If you don't have hmail, remove it.|||Because if you don't specify the port, it first tries to contact the SQL Server on one of the standard ports, and if it's firewalled, or blocked, then it takes a bit for it to realize it and then switch over. Also, if you a fairly large latency between the web and sql server, it can reduce the time significantly because there is one less connection that needs to be established, and with a normal TCP/IP connection that does a 3-way handshake to start up, it's many times the latency between the two machines.

No comments:

Post a Comment