一、Certutil 介紹 Windows有一個名為CertUtil的內置程式,可用於在Windows中管理證書。使用此程式可以在Windows中安裝,備份,刪除,管理和執行與證書和證書存儲相關的各種功能。 CertUtil的一個特性是能夠從遠程URL下載證書或任何其他文件,因為certutil是w ...
Sysbench簡介
Sysbench是一款多用途基準測試工具,可對CPU、記憶體、I/O甚至資料庫性能進行測試。它是一個基本的命令行工具,提供了直接、簡便的系統測試方法。github地址:https://github.com/akopytov/sysbench 。
主要功能:
- CPU: 衡量CPU執行計算密集型任務的能力。
- 記憶體: 衡量記憶體子系統的性能。
- 磁碟I/O: 衡量磁碟讀寫速度。
- 資料庫: 衡量資料庫的性能,包括 OLTP(聯機事務處理)和TPC-C基準測試。
- 其他: Sysbench還支持其他類型的測試,例如線程性能和網路延遲。
Sysbench的主要特點包括:
- 開源: Sysbench 是一個開源軟體,可以免費使用和修改。
- 跨平臺: Sysbench 支持多種操作系統,包括 Linux、Windows、macOS 和 Solaris。
- 多線程: Sysbench 支持多線程測試,可以充分利用多核 CPU 的性能。
- 模塊化: Sysbench 的架構是模塊化的,可以擴展支持新的測試類型和功能。
- 易用性: Sysbench 提供命令行界面和 Lua 腳本支持,易於使用和配置。
Sysbench 常用於以下場景:
- 性能測試: 評估系統的性能瓶頸併進行優化。
- 資料庫性能測試: 衡量資料庫的性能並與其他資料庫進行比較。
- 硬體評估: 評估新硬體的性能。
- 容量規劃: 規劃系統的容量以滿足未來的需求。
源碼:https://github.com/akopytov/sysbench
安裝Sysbench
首先在系統上安裝Sysbench。大多數發行版軟體源都提供了它:
# Ubuntu/Debian
$ sudo apt install sysbench
# Fedora
# dnf install sysbench
# CentOS
# yum install sysbench
# OpenSUSE
# zypper in sysbench
CPU基準測試
$ sysbench cpu --cpu-max-prime=2000 run
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Prime numbers limit: 2000
Initializing worker threads...
Threads started!
CPU speed:
events per second: 22757.61
General statistics:
total time: 10.0001s
total number of events: 227609
Latency (ms):
min: 0.04
avg: 0.04
max: 0.12
95th percentile: 0.04
sum: 9968.18
Threads fairness:
events (avg/stddev): 227609.0000/0.00
execution time (avg/stddev): 9.9682/0.00
雖然會生成包含大量統計數據的報告,但 CPU 基準測試的主要內容是"General statistics"下的"total time"。
- 其他命令:
$ sysbench cpu run
$ sysbench cpu --threads=40 run # 預設為單線程
#在檢查 CPU 在重負載下的性能時,可使用命令將 CPU 的最大質數限制從 "10000 "擴展到 "15000":
$ sysbench --test=cpu --cpu-max-prime=15000 run
# 幫助
$ sysbench cpu help
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
cpu options:
--cpu-max-prime=N upper limit for primes generator [10000]
記憶體基準測試
$ sysbench memory --threads=2 run
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
Running the test with following options:
Number of threads: 2
Initializing random number generator from current time
Running memory speed test with the following options:
block size: 1KiB
total size: 102400MiB
operation: write
scope: global
Initializing worker threads...
Threads started!
Total operations: 28555430 (2855143.49 per second)
27886.16 MiB transferred (2788.23 MiB/sec)
General statistics:
total time: 10.0001s
total number of events: 28555430
Latency (ms):
min: 0.00
avg: 0.00
max: 0.03
95th percentile: 0.00
sum: 12842.67
Threads fairness:
events (avg/stddev): 14277715.0000/1030637.00
execution time (avg/stddev): 6.4213/0.10
這裡有兩點需要考慮:"Total operations"和"transferred"。
- 其他命令:
$ sysbench memory run
$ sysbench memory --memory-oper=write run # 預設為讀
# 要測試特定條件下的記憶體,例如將記憶體塊大小從預設的 "1KiB "提高到 "1M",同時保持總記憶體容量為 "8GB"
$ sysbench --test=memory --memory-block-size=1M --memory-total-size=8G run
參考資料
- 軟體測試精品書籍文檔下載持續更新 https://github.com/china-testing/python-testing-examples 請點贊,謝謝!
- 本文涉及的python測試開發庫 謝謝點贊! https://github.com/china-testing/python_cn_resouce
- python精品書籍下載 https://github.com/china-testing/python_cn_resouce/blob/main/python_good_books.md
- Linux精品書籍下載 https://www.cnblogs.com/testing-/p/17438558.html
- https://linuxtechlab.com/benchmark-linux-systems-install-sysbench-tool/
- https://webhostinggeeks.com/howto/how-to-setup-sysbench-for-cpu-and-memory-benchmarking-on-a-linux-machine/
- https://vegastack.com/tutorials/how-to-use-sysbench-for-linux-performance-testing/
IO基準測試
在Linux系統上執行IO基準測試時,我們必須先創建一些測試文件。要創建測試文件,請使用以下命令:
$ sysbench --test=fileio --file-total-size=100G prepare
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
128 files, 819200Kb each, 102400Mb total
Creating files for the test...
Extra file open flags: (none)
Extending existing file test_file.0
...
Extending existing file test_file.127
53687091200 bytes written in 94.39 seconds (542.44 MiB/sec).
請確保選擇的測試文件大小大於記憶體容量,這樣IO進程才不會受到記憶體操作的影響。創建測試文件將根據所選大小花費一些時間。創建測試文件後,運行以下命令開始基準測試:
$ sysbench --test=fileio --file-total-size=100G --file-test-mode=rndrw --max-time=300 --max-requests=0 run
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
WARNING: --max-time is deprecated, use --time instead
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Extra file open flags: (none)
128 files, 800MiB each
100GiB total file size
Block size 16KiB
Number of IO requests: 0
Read/Write ratio for combined random IO test: 1.50
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Initializing worker threads...
Threads started!
File operations:
reads/s: 1101.01
writes/s: 734.01
fsyncs/s: 2348.98
Throughput:
read, MiB/s: 17.20
written, MiB/s: 11.47
General statistics:
total time: 300.0508s
total number of events: 1255287
Latency (ms):
min: 0.00
avg: 0.24
max: 2154.60
95th percentile: 0.46
sum: 299665.82
Threads fairness:
events (avg/stddev): 1255287.0000/0.00
execution time (avg/stddev): 299.6658/0.00
文件清理:
$ sysbench --test=fileio --file-total-size=100G cleanup
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
Removing test files...
Mysql基準測試
要對mysql進行基準測試,我們首先要在名為"test"的資料庫中創建一個有50000 的表,使用以下命令
$ sysbench --test=oltp –oltp-table-size=50000 --mysql-db=test --mysql-user=root --mysql-password=passwd prepare
操作完成後,執行以下命令啟動 Mysql Bechmarking:
$ sysbench --test=oltp --oltp-table-size=500000 --mysql-db=test --mysql-user=root --mysql-password=yourrootsqlpassword --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run
No DB drivers specified, using mysql
Running the test with following options:
Number of threads: 8
Doing OLTP test.
Running mixed OLTP test
Doing read-only test
Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Threads started!
Time limit exceeded, exiting...
(last message repeated 7 times)
Done.
OLTP test statistics:
queries performed:
read: 2253860
write: 0
other: 321980
total: 2575840
transactions: 160990 (2683.06 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 2253860 (37562.81 per sec.)
other operations: 321980 (5366.12 per sec.)
Test execution summary:
total time: 60.0024s
total number of events: 160990
total time taken by event execution: 479.3419
per-request statistics:
min: 0.81ms
avg: 2.98ms
max: 3283.40ms
approx. 95 percentile: 4.62ms
Threads fairness:
events (avg/stddev): 20123.7500/63.52
execution time (avg/stddev): 59.9177/0.00
Main parameter to check here is 'transactions per second'
transactions: 160990 (2683.06 per sec.)
測試數據清理:
$ sysbench --test=oltp --mysql-db=test --mysql-user=root --mysql-password=yourrootsqlpassword cleanup
結果解讀
總時間越短,表明系統性能越好,尤其是在比較類似測試時。不過必須將這一指標與其他指標結合起來考慮,因為測試時間越短,錯誤率越高,並不代表性能越好。
Ops/sec是系統吞吐量的直接指標。ops/sec值越高,通常意味著系統在給定時間內可以處理的操作越多,性能越好。例如,如果您運行的是資料庫伺服器,較高的ops/sec表示您的伺服器每秒可以處理更多的查詢,從而為最終用戶帶來更快的響應時間。
延遲對用戶體驗至關重要。較低的延遲意味著更快地完成操作,這對於視頻流或線上游戲等需要實時響應的任務尤為重要。如果您正在托管一個網站,較低的延遲可以加快頁面載入時間,提升用戶體驗。