[Locust] 2. Locust를 통한 언어와 프레임워크 별 테스트

2023. 3. 15. 11:43·Python/Open Source
반응형

테스트용 Locust 설정

locust.conf

locustfile = locust_impl.py
headless = true
expect-workers = 5
host = http://localhost:8000
users = 10
spawn-rate = 10
run-time = 30s

locust_impl.py

from locust import task, FastHttpUser

class TargetURL:
    ROOT = "/"
    STRING = "/string"
    JSON = "/json"
    CALC = "/calc"

class LocustImpl(FastHttpUser):

    @task
    def root(self):
        self.client.get(TargetURL.ROOT)

    @task
    def string(self):
        self.client.get(TargetURL.STRING)

    @task
    def json(self):
        self.client.get(TargetURL.JSON)

    @task
    def calc(self):
        self.client.get(TargetURL.CALC)

Python3.8 + Django4.1

import json

from django.http import HttpResponse, JsonResponse
from django.views import View

class RootView(View):

    def get(self, request, *args, **kwargs):
        return HttpResponse("Hello World")


class StringView(View):

    def get(self, request, *args, **kwargs):
        return HttpResponse("Hello" + "Django" + "World")


class JsonView(View):

    def get(self, request, *args, **kwargs):
        return HttpResponse(json.dumps({"John": "Doe"}))


class CalcView(View):

    def get(self, request, *args, **kwargs):
        return HttpResponse((30000 + 50000 - 400) * 70 / 20)

 

Python3.8 + FastAPI

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def root():
    return "Hello World"


@app.get("/string")
async def string():
    return "Hello" + "FastAPI" + "World"


@app.get("/json")
async def json():
    return {"john": "doe"}


@app.get("/calc")
async def calc():
    return (30000 + 50000 - 400) * 70 / 20

 

Go1.7 + Gin

package main

import (
    "encoding/json"
    "fmt"
    "net/http"

    "github.com/gin-gonic/gin"
)

func main() {
    gin.SetMode(gin.ReleaseMode)
    r := gin.New()
    r.GET("/", func(c *gin.Context) {
        c.String(http.StatusOK, "Hello World")
    })

    r.GET("/string", func(c *gin.Context) {
        c.String(http.StatusOK, fmt.Sprintf("%s %s %s", "Hello", "Go", "World"))
    })

    r.GET("/json", func(c *gin.Context) {
        map1 := map[string]string{"John": "Doe"}
        jsonStr, _ := json.Marshal(map1)
        c.String(http.StatusOK, string(jsonStr))
    })

    r.GET("/calc", func(c *gin.Context) {
        c.String(http.StatusOK, fmt.Sprintf("%d", ((30000+50000-400)*70/20)))
    })
    r.Run()
}

 

Java17 + SpringBoot3

@RestController
public class HomeController {

    @GetMapping("/")
    public ResponseEntity<String> home() {
        return ResponseEntity.ok("Hello World");
    }

    @GetMapping("/string")
    public ResponseEntity<String> string() {
        return ResponseEntity.ok(new StringBuffer().append("Hello").append("Spring").append("World").toString());
    }

    @Builder
    @Setter
    @Getter
    @NoArgsConstructor
    @AllArgsConstructor
    static class Sample {
        private String john;
    }

    @GetMapping("/json")
    public ResponseEntity<Sample> json() {
        return ResponseEntity.ok(Sample.builder().john("doe").build());
    }

    @GetMapping("/calc")
    public ResponseEntity<Integer> calc() {
        return ResponseEntity.ok((30000 + 50000 - 400) * 70 / 20);
    }

}

 

종합 비교

728x90
반응형
저작자표시 비영리 변경금지 (새창열림)
'Python/Open Source' 카테고리의 다른 글
  • [Python] 파이썬 출력 문자 색 변경하기
  • [Locust] 1. Locust 부하 테스트 툴(load testing tool)
  • ChatGPT를 이용한 간단한 Web App 만들기 (python, streamlit)
  • [Python] Colorful print
상쾌한기분
상쾌한기분
  • 상쾌한기분
    상쾌한기분
    상쾌한기분
  • 전체
    오늘
    어제
    • 분류 전체보기 (250)
      • Python (44)
        • Python (26)
        • Django (6)
        • Flask (4)
        • Open Source (6)
      • Kotlin & Java (5)
        • Spring (2)
        • 프로젝트 (1)
      • Go (11)
      • Database (24)
        • MySQL (21)
        • Redis (3)
      • Infrastructure (2)
        • CDC (4)
        • Kafka (5)
        • Prometheus (2)
        • Fluentd (11)
        • Docker (1)
        • Airflow (2)
        • VPN (2)
      • IT (25)
        • AI (9)
        • Langchain (8)
        • Web (18)
        • Git (8)
        • 리팩토링 (9)
        • Micro Service Architecture (8)
        • Clean Code (16)
        • Design Pattern (0)
        • 수학 (1)
        • 알고리즘 (14)
      • OS (14)
        • Centos (10)
        • Ubuntu (3)
        • Mac (1)
      • Search Engine (2)
        • ElasticSearch (1)
        • Lucene Solr (1)
      • PHP (2)
        • Laravel (1)
        • Codeigniter (1)
  • 블로그 메뉴

    • Github 방문
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    오블완
    git
    Redis
    MYSQL
    prompt
    docker
    fluentd
    Kafka
    Golang
    http
    CDC
    ollama
    go
    performance
    파이썬
    LLM
    python
    Langchain
    백준
    티스토리챌린지
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
상쾌한기분
[Locust] 2. Locust를 통한 언어와 프레임워크 별 테스트
상단으로

티스토리툴바