Thursday, August 16, 2012

[TroubleShooting] IIS run out of memory

IISOOM_1

最近在測試效能時,遇到了IIS把系統記憶體吃光,結果回傳Out Of Memory Exception,害我壓力測試就中斷了,開出Performance來看,就看到開始測試後,CPU還好,但是記憶體用量直線上升,很快的w3wp.exe就要把系統記憶體吃光光。

等到記憶體被吃光後,IIS就開始吃不太下request,然後不是沒有回應,就是回你錯誤,運氣好的話這時候就可以看到Out of Memory錯誤了XD

這時候你進Performance看,圖大概會長得像這樣(前後兩張圖我不同時間抓的,所以記憶體吃的不一樣)
IISOOM_3
看起來CPU沒啥在動(大概只有一兩個核心會變高),然後記憶體滿滿的,感覺上Server應該是不會很忙,但是這時候其實他已經接收不了request了,以前聽別人遇到這種情況,大概都會用重開IIS來解,反正等Rush hour過了應該就好了,其實這樣也沒錯,不過網站會死好一陣子就是 -_- 而且如果你的網站很熱門,那大概就掛定了。

這問題的可能應該有不少,像是保哥有一篇解決 ASP.NET 中 System.OutOfMemoryException 的問題也可以參考看看,不過將 GC 設定為 Workstation Mode (工作站模式)並不能解決我的問題XD ,我後來是用設定 Application Pools 的 Recycling 來解掉這問題的。


IISOOM_4

在Application Pool裡,可以設定他定時清理、指定時間清理、多少request後清理,或是記憶體使用達到多少後去清理Application Pool,Windows Server 2008的 Recycling Setting路徑是在

[IIS Manager] -> [Application Pool] -> [Specific Application] -> [Recycling]

我是設定記憶體用到多少就自動去清,你可以依照Server滿載時可以讓IIS吃多少記憶體去設定這個大小,這數字自己要抓好,因為有可能離峰的時候Server只用了500MB,但是尖峰時Server記憶體不算IIS就已經用掉1GB多,所以可以多觀察一下去調整這個數字。


IISOOM_2

設定成功後,在長期的尖峰負荷下,你就會看到記憶體的使用量像是這樣慢慢爬上山,然後又被清理後掉下來,還蠻有趣的,這樣的設定,在系統清理Application Pools時多少會影響一點效能,但是實際使用上是感覺不出來的,測試數據上也察覺不出有變慢,然而這樣的設定可以讓你的網站在高乘載時不會因為記憶體被吃滿就掛點,可說是每個Web Admin都必備的知識XD

1 comment:

  1. high quality replica cartier watches is a noted jewelry brand with luxurious elegance and technical innovation.replica calibre de cartier diver blue watches It has massive selection of product lines ranging from jewellery, bridal, accessories, leather goods to timepieces. In our leading online shop, we are particularly specialized in selling Swiss replica Cartier watches. There is no denying the fact that Cartier watches are within the dream list of many women. However, they come with astronomical prices which are far beyond the reach of many people. In consideration of this problem, we website provide the final products of Swiss replica Cartier watches, which are much more authentic than that of our competitors, and at a fraction of the cost of originals. Furthermore, we always take attention to details, high-end materials, fine watchmaking and advanced design.

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...