iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 22
1
自我挑戰組

谷哥 Google Cloud Platform 勇者的試煉系列 第 22

讓資料庫喘息的好幫手,GCP MemoryStore

Redis 是一個 In-memory 的 key-value database,因此常被用在需要快取(Cache)資料的情境中來降低許多後端DB資料庫的壓力

而 GCP 上也有這樣的服務就叫做 MemoryStore,這相容於Redis協定的記憶體資料庫服務,因此使用者能不改任何一行程式碼,將原本使用Redis的應用程式,轉至Cloud Memorystore上。

Redis能以單一實例部署或複製以實現高可用性,而Cloud Memorystore消除了這些複雜的部署成本。Redis通常被用於應用程式快取、遊戲排行榜,以及增量記數器等應用,因此Cloud Memorystore也能被用於這類低延遲要求的的案例中.

以下為架構示意圖
https://ithelp.ithome.com.tw/upload/images/20181022/200254810rX56LZIBv.png

本次我們就來簡單實測一下其功能,直接到儲存空間找到 MemoryStore
https://ithelp.ithome.com.tw/upload/images/20181022/20025481OfgP8Hl4cH.png

GCP貼心的地方就是能即時預估成本並動態變更即時顯示,基本與進階就在於是否有高可用,測試用我都選擇最低
https://ithelp.ithome.com.tw/upload/images/20181022/20025481Pl5gZhiELL.png

這裡有選項是否要設定Policy與Event參數
https://ithelp.ithome.com.tw/upload/images/20181022/20025481mLalRgsMMe.png

我選則優先删除最近非經常存取使用的key,用以保留最新資料數據
https://ithelp.ithome.com.tw/upload/images/20181022/20025481p0VexTBdgI.png

以下是每個參數的參考,請自行依需求決定
https://ithelp.ithome.com.tw/upload/images/20181022/200254819wru6eO8CP.png

網路我選用Default,另外最下面保留網路是指給Redis用的,不能與其他服務衝突(完全不同網段)
https://ithelp.ithome.com.tw/upload/images/20181022/20025481Br14QoNquu.png

MemoryStore建置完成
https://ithelp.ithome.com.tw/upload/images/20181022/20025481wo9itxDOwC.png

記得他的IP,目前Monitor上看沒有任何資料寫入都空的
https://ithelp.ithome.com.tw/upload/images/20181022/20025481PajBPfZLw2.png

我用一樣同地區的GCE準備SSH連入
https://ithelp.ithome.com.tw/upload/images/20181022/200254810zCV6w6XGr.png

我用Ubuntu,記得sudo su -來切換root才能做事,先安裝telnet工具測試一下MemoryStore的確是通的
https://ithelp.ithome.com.tw/upload/images/20181022/20025481wYMs6JuVxr.png

接下來要安裝Redis Tools來模擬壓測丟檔,不過需要先做更新.....剛卡了一下@@
https://ithelp.ithome.com.tw/upload/images/20181022/20025481b5zc2V55Zo.png

模組更新完後就可以正常安裝Redis Tools,按下Y繼續給他裝下去
https://ithelp.ithome.com.tw/upload/images/20181022/20025481XSgaDIrRbU.png

工具安裝完成
https://ithelp.ithome.com.tw/upload/images/20181022/20025481etKpQvxUKA.png
redis-benchmark 參數的參考資訊如下:
工具支持以下選項:
-h
伺服器的主機名(默認值為127.0.0.1)。
-p
伺服器的埠號(默認值為6379)。
-s
伺服器的套接字(會覆蓋主機名和埠號)。
-a
登錄Redis時進行身份驗證的密碼。
-c
並發的連接數量(默認值為50)。
-n
發出的請求總數(默認值為100000)。
-d
SET/GET命令所操作的值的數據大小,以字節為單位(默認值為2)。
–dbnum
選擇用於性能測試的資料庫的編號(默認值為0)。
-k
1=保持連接;0=重新連接(默認值為1)。
-r
SET/GET/INCR命令使用隨機鍵,SADD命令使用隨機值。通過這個選項,基準測試會將參數中的__rand_int__字符串替換為一個12位的整數,這個整數的取值範圍從0到keyspacelen-1。每次執行一條命令的時候,用於替換的整數值都會改變。通過這個參數,默認的測試方案會在指定範圍之內嘗試命中隨機鍵。
-P
使用管道機制處理條Redis請求。默認值為1(不使用管道機制)。
-q
靜默測試,只顯示QPS的值。
–csv
將測試結果輸出為CSV格式的文件。
-l
循環測試。基準測試會永遠運行下去。
-t
基準測試只會運行列表中用逗號分隔的命令。測試命令的名稱和結果輸出產生的名稱相同。
-I
空閒模式。只會打開N個空閒的連接,然後等待。

原文網址:https://kknews.cc/zh-tw/other/38x8ama.html
https://ithelp.ithome.com.tw/upload/images/20181022/20025481wJTQv2dWQx.png

用redis-benchmark主要就是模擬n個用戶同時向Redis發送n查詢命令的應用
redis-benchmark -h 10.130.0.3 -p 6379 -r 1000000 -n 2000000 -t get,set,l
push,lpop -P 16 -q
https://ithelp.ithome.com.tw/upload/images/20181022/20025481Nz16BIPEDt.png

從 MemoryStore 來看監視左上列表有多種參數可以檢視
https://ithelp.ithome.com.tw/upload/images/20181022/20025481JbTHoD8x05.png

最重要的Hits命中率...上面顯示100%
https://ithelp.ithome.com.tw/upload/images/20181022/20025481L0ImWCasFu.png

網路輸出入的傳輸資料量
https://ithelp.ithome.com.tw/upload/images/20181022/20025481eXt3FCF4Z0.png

還有剛剛針對get,set,lpush,lpop對各型key值的執行動作次數紀錄
https://ithelp.ithome.com.tw/upload/images/20181022/20025481obvwltHEin.png

最後順便展示 MemoryStore 每種層級的的規格表(就是網路與資料容量空間可以乘載最大範圍)
https://ithelp.ithome.com.tw/upload/images/20181022/20025481LekfwKziOk.png

好了!今天就到這啦!大家應該也累了,81...


上一篇
怕所屬地理區域服務中斷,GCP 網路服務級別提升你的高可用性
下一篇
GCP 監控分析紀錄不求人,StackDriver 前傳
系列文
谷哥 Google Cloud Platform 勇者的試煉30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言