Python 框架(Flask,tornado,fastAPI)Go 的gin框架 Java spring 框架中的性能对比

使用jmeter进行压测:

配置如下:

 

Flask 框架:

Python代码:

from flask import Flask

app = Flask(__name__)



@app.route('/')
def hello_world():
    return 'Hello, World!'

if __name__ == '__main__':
    app.run(port=8080)

测试结果:

 

Tornado 框架:

import tornado.web

class MainHandler(tornado.web.RequestHandler):
    async def get(self):
        # await asyncio.sleep(1)
        self.write("Hello, world!")

if __name__ == "__main__":
    app = tornado.web.Application([(r"/", MainHandler)])
    app.listen(8886)
    tornado.ioloop.IOLoop.current().start()

测试结果:

 FastAPI 框架:

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
    return {"Hello": "World"}

if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host="0.0.0.0", port=8885)

测试结果:

 GO gin 框架

package main

import (
"github.com/gin-gonic/gin"
"net/http"
)

func main() {
	// 创建一个 Gin 引擎
	r := gin.Default()

	// 定义一个路由处理函数
	r.GET("/", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{"message": "Hello, Gin!"})
	})

	// 启动 Gin 服务器
	r.Run(":8889")
}

  测试结果:

 Java spring框架:

package com.example.mytest.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;


@Controller
public class IndexController {
    @GetMapping("/")
    public String test(HttpServletRequest request, Model model)  {
        return  "hello world";
    }
}

  测试结果:

 

posted @ 2023-09-08 15:19  Py浪涛  阅读(431)  评论(0编辑  收藏  举报
你想听歌吗o((;=゚ 3゚ =))o~♪