2016年8月14日 星期日

NanoProfiler 設定 - Profiling Configuration

這邊簡單說明 NanoProfiler 的一些設定修改的內容。

 


3. Profiling Configuration · ef-labs/nanoprofiler Wiki

https://github.com/ef-labs/nanoprofiler/wiki/3.-Profiling-Configuration

 

將近兩個月沒有寫文章了,一時間還真不知道要寫什麼,就先從 NanoProfiler 的 Configuration 來說起,在 NanoProfiler 的第一篇文章「使用 NanoProfiler 對 ASP.NET Web API 進行性能監控」裡,在文章的 Step.3 修改 Web.Config 就有稍微提到 NanoPrifiler 的 Configuration 設定的修改,

image

<nanoprofiler circularBufferSize="200" storage="EF.Diagnostics.Profiling.Storages.Json.JsonProfilingStorage, NanoProfiler.Storages.Json">
    <filters>
        <add key="_tools" value="_tools/" type="Contain" />
        <add key="exts" value="ico,jpg,js,css" type="EF.Diagnostics.Profiling.Web.ProfilingFilters.FileExtensionProfilingFilter, NanoProfiler.Web" />
        <add key="ViewProfilingLogsHandler" value="ViewProfilingLogsHandler.*" type="regex" />
    </filters>
</nanoprofiler>

 

這一組設定裡,先說明 CircularBuffersize,這是指每個週期暫存 Profiler 資料的數目,預設值為 100,

https://github.com/ef-labs/nanoprofiler/blob/2.0/src/NanoProfiler/Configuration/NanoProfilerConfigurationSection.cs

而我通常會設定為 200,也就是說每次的 Profiling 記錄只有最近的 200 筆,然後沒有將記錄存放到其他的儲存裝置的話,就是存放在記憶體中,不是最近 200 筆的記錄就會被丟棄。

當然也可以將 CircularBufferSize 調整為很大的數字,但相對的就是會佔用 Server 的記憶體空間,所以該用多少的數目,就看開發者與維護者的需要,畢竟 Profiling Log 並不是所有人都會時時刻刻的去看,而是當有效能問題或是程式作更新調整的前後會需要用到,而在其他時候並不會有多少機會進去看。

 

NanoProfiler 的 Configuration 在之前的 1.x 版本是必須要在 Global.asax 裡的 Application_Start 事件裡做設定,是到了 2.x 版本後才增加了可以將 Configuration 放在 Web.Config 裡的修改,一開始作者並沒有同步更新 Wiki 文件的說明,而且 1.x 與 2.x 在設定上有不小幅度的修改,所以當時摸索了一段時間,在毫無頭緒的時候,我就發出了 issue「https://github.com/ef-labs/nanoprofiler/issues/2」,就在發出 issue 後的不久,我就找出了怎麼在 Global.asax 裡修改 CircularBufferSize 的方式,如下:

ProfilingSession.CircularBuffer = new CircularBuffer<ITimingSession>(size: 200); 

而最後作者也修改了 Wiki 的內容,

https://github.com/ef-labs/nanoprofiler/wiki/3.-Profiling-Configuration

image

 

除了 CircularBufferSize 設定外,另外的設定是針對過濾行為,一個是針對目錄而另一個是針對檔案副檔名,當 request 進入網站後,凡是有讀取設定過濾的目錄名稱與檔案副檔名就不會記錄下來。

如果是過濾多個目錄的話,並不是像設定過濾副檔名的方式,不是在 value 將多個過濾的名稱與逗號分隔,多個目錄的過濾應該是要在 NanoProfiler 的 Section 裡去增加多個 key value 設定。

 


這一篇就這樣,說明 NanoPrifiler 的 Configuration,雖然簡單也是相當重要的。此外雖然 Configuration 在 Web.Config 與 Global.asax 裡都可以設定,但是我比較建議優先選擇使用在 Web.Config 裡的設定方式,會比放在 Global.asax 裡還來得方便與彈性。

 

相關連結

mrkt 的程式學習筆記: 使用 NanoProfiler 對 ASP.NET Web API 進行性能監控

3. Profiling Configuration · ef-labs/nanoprofiler Wiki

https://github.com/ef-labs/nanoprofiler/blob/2.0/src/NanoProfiler/ProfilingFilters/NameContainsProfilingFilter.cs

https://github.com/ef-labs/nanoprofiler/blob/2.0/src/NanoProfiler/Configuration/NanoProfilerConfigurationSection.cs

https://github.com/ef-labs/nanoprofiler/blob/2.0/src/NanoProfiler.Web/ProfilingFilters/FileExtensionProfilingFilter.cs

Wikipedia – CircularBuffer

 

以上

3 則留言:

  1. Kevin大大,我已經實際參考您的部落格將NanoProfiler使用於專案,不過目前遇到無法加入權限或設定remote only ,想請問您如何做權限卡控呢?

    回覆刪除
    回覆
    1. 我從來沒有說過 nanoprofiler 可以用即有的權限機制或用什麼 remote only 的方式去做,不要自行腦補去用 elmah 的方式,open source 都放在 github 上,可以去研究看看呀

      刪除
  2. 好的,我再研究source code

    回覆刪除

提醒

千萬不要使用 Google Talk (Hangouts) 或 Facebook 及時通訊與我聯繫、提問,因為會掉訊息甚至我是過了好幾天之後才發現到你曾經傳給我訊息過,請多多使用「詢問與建議」(在左邊,就在左邊),另外比較深入的問題討論,或是有牽涉到你實作程式碼的內容,不適合在留言板裡留言討論,請務必使用「詢問與建議」功能(可以夾帶檔案),謝謝。