# JMeter 壓力測試 [TOC] ###### tags: `chatgpt` --- ## Tl;DR > 用 JMeter 進行壓力測試。 > > 1. POST https://sso.bloxmith.dev/connect/token 取得 access token 然後將回應的 `"access_token"` 值暫存到一個變數,這個 endpoint 以 `Content-Type: application/x-www-form-urlencoded` 並帶入下列參數:`client_id=client_id`、`client_secret=client_secret`、`grant_type=grant_type`、`scope=scope` > 2. GET https://api.bloxmith.dev/{version}/player/{playerId}/mail 帶入步驟一暫存的 Bearer token,`{version}` 要能在執行前指定,`{playerId}` 則從一清單讀取 以下是使用 JMeter 進行壓力測試的步驟: 開啟 JMeter,建立一個新的 **Test Plan**。 建立一個 **Thread Group**,設定 **Number of Threads** 為希望模擬的使用者數量,**Ramp-Up Period** 為希望模擬的使用者數量需要達到的時間,**Loop Count** 則可以設定為永久迴圈或設定一個特定的次數。 建立一個 **HTTP Request Defaults**,設定預設的協定、伺服器名稱及埠號等資訊。 建立第一個 **HTTP Request**,設定方法為 POST,伺服器名稱為 `https://sso.bloxmith.dev`,路徑為 **`/connect/token`**。在 **Body Data** 中輸入以下參數:`client_id`、`client_secret`、`grant_type`、`scope`,設定 `Content-Type` 為 `application/x-www-form-urlencoded`。接著在「**Send Parameters With the Request**」下方的「**Add Authorization**」中新增一個「**Bearer Token**」,**Value** 則輸入一個暫存 **`access_token`** 的變數名稱。 建立第二個 **HTTP Request**,設定方法為 GET,伺服器名稱為 `https://api.bloxmith.dev`,路徑為 `/{version}/player/{playerId}/mail`。在 **Path** 中輸入 `version`,使用 JMeter 提供的 **User Parameters** 或 **CSV Data Set Config** 等元件,讓 `version` 可以在執行前指定。在 **Path** 中的 `playerId` 則可以使用 **CSV Data Set Config** 元件,從一個清單中讀取 `playerId`。在「**Send Parameters With the Request**」下方的「**Add Authorization**」中新增一個「**Bearer Token**」,**Value** 則設定為步驟一暫存的 **`access_token`** 變數。 執行 **Test Plan**,觀察結果並進行調整,例如調整**使用者數量**、**Ramp-Up Period**、**迴圈次數**等。
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up