Constant SQL Server 80% CPU Utilization - asp.net

We have a small (for now) Asp.Net MVC 5 website on a dedicated VPS. When I go to the server and fire-up task manager, I see that "SQL Server Windows NT - 64 bit" is using around 80% of CPU and 170MB of RAM and IIS is using 6% CPU and 400MB of RAM. Server Specs are:
CPU 1.90Ghz dual core
Memory 2GB
Windows Server 2012
SQL Server Express 2012
Disk Space: 25GB, 2.35 Free.
The database is not very big. Its backup is less than 10MB.
I have tried to optimize the website as much as I could. I added caching to a lot of controllers and implemented donut caching for quite a lot of controllers. But today, even though there were only 5 users online, our search wouldn't work. I restarted the Windows on the server and it started working but I got the high CPU usage the minute server started. Interestingly when I open the SQL Server Management Studio and try to get the report for top CPU-consuming queries it says that there are no queries currently consuming any CPU!!! But at the same time I can see that SQL server is consuming a lot of CPU. How can I examine what is taking all the CPU? Below is a picture from the server:
I was/am very careful with designing and implementing the website. All the database access is through latest version of Entity Framework. I just wonder if the server's specs are low. Any help would be very much appreciated.
Update:
Here's the result of the sp_who2 stored procedure.

This could happen if the memory set to use is more than the available memory on the box. The default memory setting of 2147483647MB. In our case the AWS box had only 30.5 GB so we changed the setting to 26GB and the CPU usage fell to 40%. You generally want to leave 20% of memory for OS and its operations.

I would agree running SQL Profiler to spot large query durations and large write operations. Try running perfmon and spotting any potential connection leaks (reclaimed connections).

Related

IIS 6 RAM Allocation on Windows Server 2003

I have my IIS 6 running my website. It is on a Windows Server 2003 which has 4GB of RAM. I run SQL intensive code after the user submits a form (math statistics stuff). This process is not threaded (should it be, especially if 2 or more users run the same thing?). But my process seems to consume only a couple of GBs of memory and the server crawls. How do I get my IIS process to use nearly all the memory?
I see on other sites that its 2GB or 3GB allocated using boot.ini. But is there another way for the process to use memory? If I make it multithreaded, will there be a process for each thread?
If there is still memory free for IIS, it does not need more. Even if you give it more memory it will perform better. It is good to see some memory is not used and can be used for other processes as IIS. If you want to make is multi threading, it depends on what you do parallel if more memory is used, and if you gain any performance.
The basic here is to start with your requirements and see what peak use you can have. Then make a performance test to see if your machine can handle that load. To be sure you can handle some more do an other test to see the peek load your machine can handle. Then you will know if you have to invest any more time.
Check you database server to see if you bottleneck is not on that machine, most developers forget optimizing and maintaining their databases.

SQL Server 2008 R2 Express on 1 GB RAM virtual?

i have an ASP.NET application (website, catalog-like). No high load expected (not more than 50 concurrent users, lets say, and 95% just read - it is a website), but it has some specific needs, so i cant host it on shared hosting, and going for hosted virtual server. Configuration is like this - 2 GHz core (agregated 1:5), 1024 dedicated RAM, 30GB disk space. It is running Windows Server 2008 R2 Web.
Now the questions
it is a good idea to install and run SQL server 2008 R2 Express on this virtual ? Limitations are OK (anyway I have only 1 core and 1GB RAM, 10 GB per DB is perfectly fine), but how about performance ? I dont want it to use all available memory, because the ASP.NET app needs some too because of intensive caching (so maybe few hundreds MBs).
Can i set max server memory for SQL express to (lets say) 500 MB and expect fair performance? (only 1 small DB - for some time it will be under that 500 MB, and for a long time under 1 GB).
Additionally, are there any options i can use to minimize memory footprint/requirements of SQL server express ? (besides NOT installing reporting services, fulltext serach and replication - non of this is needed in my app)
1.it is a good idea to install and run SQL server 2008 R2 Express on this virtual ?
No. 30gb disc space area laready below what is recommended for windows - ading sql server wont help. On top, you never know how crappy the disc subsystem is, and fast discs are what makes ad atabase fly. DB perforamcne to a large part is controleld by the performance of the disc subsystem and that nromally sucks on virtual discs provided by non specialised hosters.
2.Can i set max server memory for SQL express to (lets say) 500 MB and expect fair performance?
Can i load only 100kg on a car and it is suitable= DEPENDS WHAT YOU DO. 500mb for a 10gb database may or may not be enough, depends on usabe patterns.
3.Additionally, are there any options i can use to minimize memory footprint/requirements of SQL
server express ?
This is so totalyl not hjow sql server works. Databases want big ram to use it as cache. Minimize it - sure. Then isntead of RAM you bburn IOPS which is a harder resource to get.
I personally think that aproduction server - even a vps - that is so much less powerfull thean a cheap laptop is totally the wrong approach.

maximum RAM avaiable for an asp.net app

If I buy a server on which I'll be able to put as much RAM as I want, how much RAM can I make available for my asp.net web app using the latest versions of everything?
Reason I'm asking is that I plan to use InProc session to its full potential.
Thanks.
Any process on a 32-bit Windows Server is limited to 2GB unless you have set the /3GB switch in your boot.ini file, in which case a process can use 3GB.
If you're using a 64-bit server you will be limited by what the server can offer.
See Memory Limits for Windows and Windows Server Releases.
You may also need to increase the Max memory the application pool in IIS can use.
Also see the maximum memory allowed for w3wp worker processes on 64-bit IIS.
Are expecting a heavy load on the server? Had you thought about using the database to store sessions, or MVC .Net with no session state?
Increasing the memory to 6 GB or more on the server won't help because 4 GB is the
maximum for addressable memory for Win-32. You would have to go to Win 64 in
order to add more memory to the server configuration.
If its a dedicated is box, you can try running with the 3GB switch,
which would allow the asp.net to use up to 3GB.
You should also check what your current max memory is set to...!?

SqlCE as a DB under asp.net - what are the disadvantages?

I can't buy a the SQL server full/express plan on my hosting environment and I was thinking of using SQLCE with EF 4.0
expected user load is 1000-2000 per day.
"user load is 1000-2000 per day"
This isn't a particularly good measure of what load your database will be under.
You need to measure things like:
the number and complexity of your queries.
What kind of writes (insert/update/delete) will need to be performed.
How many of those a user might perform.
The amount of data being dealt with in the above queries.
Whether you can cache any of the results of queries.
For instance, I know of systems where having 1000 users required a cluster of high end servers to deal with the load.
If you can model what the performance is like for 50, 100, and 500 users - that could give you an idea of whether you can deal with this load.
FWIW: SQL Server Express Edition is free for commercial usage.
The sqlserverCe-dll (as well as the similar SQLite-dll) has 32bit native code inside. so there might be some 32/64bit issues when running on a 64bit system.
I am not shure if there is already a 64bit sqlserverCe-dll.
SQL Server Compact will run under medium trust under ASP.NET 4, and supports both x64 and x86 platforms. It is limited to max 256 concurrent connections. It is file based, and not quite as robust as SQL Server, and does not support recovery to a point in time.

w3wp.exe has high cpu usage on every request

I'm running a Windows 2008 server (a VPS with 1GB of RAM), with SQL Server Express and IIS 7 installed. On it I'm hosting a NopCommerce 1.7 website, with a database of around 26 000 products.
Right now I'm the only user of the website (it's in development) and I'm getting rather bad performance from it. To be more specific every time I make a request, the worker process goes to 90-100% CPU usage for a few seconds. Is it me or this is a lot for a 1 user NopCommerce website? Any ideas why this happens and what I can do to rectify it or further investigate?
PS: the worker process uses between 100MB-400MB of memory (private working set), and SQL Server with this database, around 160MB. Do you have any suggestions other then the obvious one to get more RAM? I intend to get one more GB but I fear this will not solve the cpu usage problem.
You've already stated you're going to get more RAM, but don't be surprised how much a lack of RAM can impact the CPU. If your RAM is not able to hold large objects efficiently because of lack of space (and I'd say using 40% of available RAM qualifies), then the CPU has to work harder to page things in and out of virtual memory. 90% is a little overkill for this, but with the server specs you give it's not impossible.
The most likely problem is that there is a hole in your code somewhere. My guess is that you have either an infinite loop or a direct memory leak (resources open during requests that aren't closed perhaps?). Your best bet would be to get the IIS Debug Diagnostics tool, install it and set up reports to find out what is going on directly on the server.

Resources