AWS DynamoDB做爲公有云的NoSQL 數據庫,在不少業務環境和系統都被大量使用。 做爲託管服務,傳統DBA解脫了調優的壓力,可是實際使用過程當中,也須要遵照DynamoDB的遊戲規則,才能更好的發揮性能。html
而不少業務場景,在上線前,要評估生產環境的資源分配狀況,如DynamoDB WCU/RCU等。那就須要對數據庫作相應的壓力測試,並根據測試狀況,預留相應的資源。git
這個時候,一個有效的,被普遍承認的壓力測試軟件,纔是壓力測試的核心。github
這裏我選擇YCSB,全稱爲Yahoo! Cloud Serving Benchmark ,是Yahoo公司的一個用來對雲服務進行基礎測試的工具。數據庫
百度一下,YCSB的文章不少,可是針對DynamoDB的,居然只有一篇,並且仍是日文的。網絡
無奈,本身研究Github文檔吧。app
下面開始流水帳式一步步記錄個人按照和測試過程:ide
1. YCSB下載和安裝工具
wget https://github.com/brianfrankcooper/YCSB/releases/download/0.15.0/ycsb-0.15.0.tar.gz tar xfvz ycsb-0.15.0.tar.gz cd ycsb-0.15.0
2.測試是否能夠運行oop
bin/ycsb.sh load basic -P workloads/workloada bin/ycsb.sh run basic -P workloads/workloada
3.查看關於dynamoDB部分的測試方法和具體配置性能
cd ycsb-0.15.0 cd dynamodb-binding/ cat README.md
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Benchmark $YCSB_HOME/bin/ycsb load dynamodb -P workloads/workloada -P dynamodb.properties $YCSB_HOME/bin/ycsb run dynamodb -P workloads/workloada -P dynamodb.properties # Properties $DYNAMODB_HOME/conf/dynamodb.properties $DYNAMODB_HOME/conf/AWSCredentials.properties ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4. 準備dynamoDB的鏈接信息,
查找終端節點連接:
https://docs.amazonaws.cn/aws/latest/userguide/endpoints-Ningxia.html
$ cat dynamodb/conf/dynamodb.properties dynamodb.awsCredentialsFile = dynamodb/conf/AWSCredentials.properties dynamodb.primaryKey = ppktest dynamodb.endpoint = http://dynamodb.cn-northwest-1.amazonaws.com.cn
5. 準備AWS AK/SK 信息
$ cat dynamodb/conf/AWSCredentials.properties accessKey = XXXXXXXXXXXXXXXXXXXX secretKey = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6. 建立dynamoDB表:
很簡單,可是也耗費我很長時間的一個小坑。dynamoDB的表名,YCSB只能是默認表名usertable,不能夠本身取名字(應該是能改的,嘗試去找配置文件,可是沒有找到)。這也就能理解,爲何第4步的dynamodb.properties中,只須要提供的是主鍵名dynamodb.primaryKey ,而不是表名了。另外,只能設置主鍵,不能設置sort key,否則也會報錯(訂正: 能夠經過dynamodb.properties中的hash_and_range參數來實現sort key設置):
~~~~~~~~~~~~~~~~表名若是不是usertable,會遇到下面報錯~~~~~~~~~~~~~ 0 [Thread-1] INFO com.yahoo.ycsb.db.DynamoDBClient -dynamodb connection created with http://dynamodb.cn-northwest-1.amazonaws.com.cn DBWrapper: report latency for each error is false and specific error codes to track for latency are: [] 185 [Thread-1] ERROR com.yahoo.ycsb.db.DynamoDBClient -com.amazonaws.AmazonServiceException: The provided key element does not match the schema (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: 2J7JAI7ME2OCD2DR7VCQQFG6HJVV4KQNSO5AEMVJF66Q9ASUAAJG) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~設置sort key,會遇到下面錯誤~~~~~~~~~~~~~~~~~~~~~~ Starting test. 0 [Thread-1] INFO com.yahoo.ycsb.db.DynamoDBClient -dynamodb connection created with dynamodb.cn-northwest-1.amazonaws.com.cn DBWrapper: report latency for each error is false and specific error codes to track for latency are: [] 412 [Thread-1] ERROR com.yahoo.ycsb.db.DynamoDBClient -com.amazonaws.AmazonServiceException: One or more parameter values were invalid: Missing the key sortkeytest in the item (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: GH5CTDSTDPG99AL0Q1PF962DPJVV4KQNSO5AEMVJF66Q9ASUAAJG) Error inserting, not retrying any more. number of attempts: 1Insertion Retry Limit: 0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7. 準備壓力測試參數文件,YCSB已經準備默認的workloada,workloadb,workloadc.....等常規業務模擬場景,能夠直接使用,也能夠根據需求更改具體參數
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Read/update ratio: 95/5 # Default data size: 1 KB records (10 fields, 100 bytes each, plus key) # Request distribution: zipfian recordcount=10000000 operationcount=100000 workload=com.yahoo.ycsb.workloads.CoreWorkload readallfields=true readproportion=0.95 updateproportion=0.05 scanproportion=0 insertproportion=0 requestdistribution=zipfian ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8. 加載數據到DynamoDB
cd ycsb-0.15.0 ./bin/ycsb.sh load dynamodb -P workloads/ddbworkload -P dynamodb_home/conf/dynamodb.properties
9. 加載完數據後,表信息
10. 進行壓力測試
./bin/ycsb.sh run dynamodb -P workloads/ddbworkload -P dynamodb_homeonf/dynamodb.properties -threads 100 -target 100
輸出結果以下:
[OVERALL], RunTime(ms), 432143## 總共運行時間432秒 [OVERALL], Throughput(ops/sec), 231.40488218020423## 平均吞吐量 [TOTAL_GCS_PS_Scavenge], Count, 180 [TOTAL_GC_TIME_PS_Scavenge], Time(ms), 200 [TOTAL_GC_TIME_%_PS_Scavenge], Time(%), 0.046280976436040844 [TOTAL_GCS_PS_MarkSweep], Count, 0 [TOTAL_GC_TIME_PS_MarkSweep], Time(ms), 0 [TOTAL_GC_TIME_%_PS_MarkSweep], Time(%), 0.0 [TOTAL_GCs], Count, 180 [TOTAL_GC_TIME], Time(ms), 200 [TOTAL_GC_TIME_%], Time(%), 0.046280976436040844 [READ], Operations, 95111## 有95111個更新操做 [READ], AverageLatency(us), 4202.653026463816## 平均響應時間(微秒) [READ], MinLatency(us), 2478## 最小響應時間(微秒) [READ], MaxLatency(us), 635391 ## 最大響應時間(微秒) [READ], 95thPercentileLatency(us), 4239 [READ], 99thPercentileLatency(us), 4863 [READ], Return=OK, 95111 ## 有95111個更新操做返回0(0=成功) [CLEANUP], Operations, 1 [CLEANUP], AverageLatency(us), 4.0 [CLEANUP], MinLatency(us), 4 [CLEANUP], MaxLatency(us), 4 [CLEANUP], 95thPercentileLatency(us), 4 [CLEANUP], 99thPercentileLatency(us), 4 [UPDATE], Operations, 4889 [UPDATE], AverageLatency(us), 6465.101656780527 [UPDATE], MinLatency(us), 4448 [UPDATE], MaxLatency(us), 1715199 [UPDATE], 95thPercentileLatency(us), 6099 [UPDATE], 99thPercentileLatency(us), 6739 [UPDATE], Return=OK, 4889
11. 在YCSB壓測方式以外,若是隻是想測試一下RCU/auto scaling,也能夠經過scan的方式,在多個窗口同時執行,
(查詢usertbale 行數)
aws dynamodb scan --table-name usertable --select "COUNT" { "Count": 5529465, "ScannedCount": 5529465, "ConsumedCapacity": null }
瞬間就達到我這個帳號 DynamoDB的8000 limit了. (訂正:8000不是limit,每一個dynamoDB默認的RCU和WCU配額分別是40000,我這裏是EC2(用來執行table scan命令的機器)的網絡出流量達到瓶頸了)
12. 換個大機型(EC2 用來執行table scan命令),經過多個窗口,同時執行table scan操做,能夠看到,輕鬆達到2W以上 RCU
至此,本文結束,YCSB做爲簡單易用的NoSQL壓測工具,總體感受還不錯,還有不少參數和細節,須要有時間深刻研究一下。
參考文檔:
Github YCSB https://github.com/brianfrankcooper/YCSB
YCSB dynamodb-autoscaling検証(日文) https://qiita.com/lawliteqed/items/d5d726e73803b891bb57
DynamoDB官方文檔: https://docs.amazonaws.cn/amazondynamodb/latest/developerguide/Introduction.html
小注: 在好友的提醒下,有三點錯誤,進行訂正。沒有直接改原文,而是經過括號,標註和解釋一下。留有原汁原味的學習歷程。