Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can low memory on IIS server cause SQL Timeouts (SQL Server on separate box)?

I have an IIS Web Server that hosts 400 web applications (distributed across 30 application pools). They are both ASP.NET applications and WCF Services end points. The server has 32GB of RAM and is usually running fast; although it's running at 95% memory usage. Worker processes each take between 500MB and 1.5GB of RAM.

I also have another box running SQL Server. That one has plenty of free memory.

Sometimes, the Web Server starts throwing SQL Timeout exceptions. A few per minutes at first and rapidly increasing to hundreds per minute; effectively making the server down. This problem affects applications in all pools. Some requests still complete but most of them don't. While this happens the CPU usage on the server is around 30% (which is the normal load on that box).

While this is happening, we can still use SQL Server Management Studio (from the IIS Server) to execute requests successfully (and fast).

The fix is to restart IIS. And then everything goes back to normal until the next time.

Because the server is running with very low memory, I feel like this is the cause. But I cannot explain the relationship between low memory and sudden bursts of SQL Timeout exceptions.

Any idea?

like image 259
Sylvain Avatar asked Jan 15 '13 21:01

Sylvain


People also ask

What happens when SQL Server runs out of memory?

SQL Server doesn't move data from memory (the buffer pool) into tempdb in that way. It uses a "least recently used" caching strategy (in general), so if there is memory pressure, and new data needs to be pulled into memory, SQL Server will kick out the LRU data from the buffer pool to accommodate the new data.

How do I know if my SQL Server needs more memory?

Sometimes, you gotta look at what queries that are currently running are waiting on. For that, go grab sp_WhoIsActive. If you see queries constantly waiting on stuff like this, it might be a sign you need more memory, because you have to keep going out to disk to get what queries need to use.

Can SQL run out of memory?

In-Memory OLTP uses more memory and in different ways than SQL Server does. It is possible that the amount of memory you installed and allocated for In-Memory OLTP becomes inadequate for your growing needs. If so, you could run out of memory.


1 Answers

Memory pressure can trigger paging and garbage collection. Both introduce latency which would not be present otherwise.

GC'ing 32GB of data can take seconds. Why would all app processes GC at the same time? Because at about 95% memory utilization Windows sets a "low memory" event that the CLR listens to. It will try to release memory to help other processes.

If the applications get into a paging frenzy that would also explain huge delays in normal execution.

This is just guessing, though. You can try proving it by looking at the "Hard page faults/sec" counter. There also must be a counter for "full GC" or "Gen 2 GC".

The fix would be running at a higher margin to the physical memory limit.

like image 165
usr Avatar answered Oct 08 '22 08:10

usr