ローカストパフォーマンス-ゼロベースの紹介シリーズ(14)-ロギングアプリケーション

この記事では、パフォーマンステスト中のLocustのログ管理について紹介します。これは、テストプロセスに不可欠なステップです。後の段階で問題が発生した場合、詳細またはデバッグ可能なログメカニズムにより、問題のトラブルシューティングまたは解決時に考えられる手がかりが得られます。

ケースを使用して、ロギングの使用法を説明します。locust_file.pyは次のとおりです。ロギングでは、python標準ライブラリのモジュールが使用されます。

from locust import HttpUser, task, between
import logging as log

class MyUser(HttpUser):
    wait_time = between(3,5)

    @task
    def open_blog(self):
        with self.client.get("/13734261/2540530",catch_response=True) as response:
            if response.status_code != 200:
                response.failure("Threre maybe some issues in the requests.")
                log.error("请求执行有错误。")
            elif response.elapsed.total_seconds() > 5:
                response.failure("Request took too long")
                log.error("请求响应超过5秒钟")

            log.info("请求执行成功!")

このように、Locustがパフォーマンステストを実行しているとき、コマンドラインコードは次のように記述できます
。locust-flocust_file_chapter13.py--logfile = locust.log

このようにして、デフォルトのコンソールにログを表示する代わりに、現在のディレクトリにファイル「locust.log」を作成します。上記のローカストファイルによると、ログサンプルは次のとおりです。

[2020-12-03 21:18:28,159] xx.local/INFO/locust.main: Starting web interface at http://:8089
[2020-12-03 21:18:28,167] xx.local/INFO/locust.main: Starting Locust 1.1.1
[2020-12-03 21:18:58,420] xx.local/INFO/locust.runners: Hatching and swarming 1 users at the rate 1 users/s (0 users already running)...
[2020-12-03 21:18:58,421] xx.local/INFO/locust.runners: All users hatched: MyUser: 1 (0 already running)
[2020-12-03 21:18:58,941] xx.local/INFO/root: 请求执行成功!
[2020-12-03 21:19:04,164] xx.local/INFO/root: 请求执行成功!
[2020-12-03 21:19:09,266] xx.local/INFO/root: 请求执行成功!
[2020-12-03 21:19:12,799] xx.local/INFO/root: 请求执行成功!
[2020-12-03 21:19:17,171] xx.local/INFO/root: 请求执行成功!
[2020-12-03 21:19:20,612] xx.local/INFO/root: 请求执行成功!
[2020-12-03 21:27:18,787] xx.local/INFO/locust.main: Running teardowns...
[2020-12-03 21:27:18,787] xx.local/INFO/locust.main: Shutting down (exit code 0), bye.
[2020-12-03 21:27:18,787] xx.local/INFO/locust.main: Cleaning up runner...

ローカストパフォーマンス-ゼロベースの紹介シリーズ(14)-ロギングアプリケーション

おすすめ

転載: blog.51cto.com/13734261/2571570