今天跟
峽谷金橋
聊天,詢問起Logstash的性能,金橋提示說Logstash中json的序列化是浪費性能的一方面。因而便有了下面的測試:json
首先須要造一份數據,數據能夠經過logstash的generator來造。ruby
input{ generator{} } output{ file{ path => "E:/test.log" } }
生成的數據格式以下:框架
{"message":"Hello world!","@version":"1","@timestamp":"2016-07-12T13:46:48.821Z","host":"DESKTOP-1GPAD95","sequence":0} {"message":"Hello world!","@version":"1","@timestamp":"2016-07-12T13:46:48.824Z","host":"DESKTOP-1GPAD95","sequence":1} {"message":"Hello world!","@version":"1","@timestamp":"2016-07-12T13:46:48.824Z","host":"DESKTOP-1GPAD95","sequence":2} {"message":"Hello world!","@version":"1","@timestamp":"2016-07-12T13:46:48.825Z","host":"DESKTOP-1GPAD95","sequence":3} ...
測試的思路是,從test.log文件中讀取數據。而後計算必定範圍內寫入的日誌數量(靠人工計算啦!)性能
codec => json
的測試的腳本以下:測試
input{ file{ path => "E:/test.log" codec => json start_position => "beginning" } } filter{ ruby { code => "event['tag'] = Time.now" } } output{ file{ path => "E:/json_result3.log" } }
codec => plain
的測試的腳本以下:設計
input{ file{ path => "E:/test.log" codec => plain start_position => "beginning" } } filter{ ruby { code => "event['tag'] = Time.now" } } output{ file{ path => "E:/json_result3.log" } }
這裏在每條事件中寫入了1個時間戳字段,而後打開文件,定位隨機定位一個開始的秒數,好比從2016-07-12 22:12:44
到2016-07-12 22:12:54
這十秒鐘,產生的日誌數量就是解析的數量。日誌
爲了不機器差別以及運行環境的差別,所帶來的偏差,這裏每一個codec執行了3次,計算得出的數據大體以下:code
日誌名稱 | 起始時間(行數) | 結束時間(行數) | 總行數(結束-起始) |
---|---|---|---|
json_result1.log | 2016-07-12 22:12:44(63) | 2016-07-12 22:12:54(34728) | 34665 |
json_result2.log | 2016-07-12 22:26:18(517) | 2016-07-12 22:26:28(27599) | 27082 |
json_result3.log | 2016-07-12 22:27:48(147) | 2016-07-12 22:27:58(30352) | 30205 |
plain_result1.log | 2016-07-12 22:13:41(300) | 2016-07-12 22:13:51(50437) | 50137 |
plain_result2.log | 2016-07-12 22:22:32(187) | 2016-07-12 22:22:42(53525) | 53338 |
plain_result3.log | 2016-07-12 22:24:43(360) | 2016-07-12 22:24:53(43580) | 43220 |
測試結果也能夠參考下面的圖片,更爲直觀一點:對象
從測試的結果來看,的確plan要比json性能高一些,也就是說logstash在作json序列化的時候浪費了不少的性能。blog
這就給想要本身寫數據採集框架的朋友一點提示——Event對象該如何設計?
PS:因爲我選取的數據樣本範圍都是第一個完整的10秒鐘,所以能夠看到採集的數據量比較少,平均每秒還不到1w.
這可能受多方條件影響: