728x90
반응형
테스트용 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] 파이썬 출력 문자 색 변경하기 (0) | 2023.04.04 |
---|---|
[Locust] 1. Locust 부하 테스트 툴(load testing tool) (0) | 2023.03.15 |
ChatGPT를 이용한 간단한 Web App 만들기 (python, streamlit) (4) | 2023.03.14 |
[Python] Colorful print (0) | 2021.08.12 |
[Python 오픈소스] Diagrams (0) | 2021.01.13 |