• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

go之web框架 iris

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

前言

最近开始学习GO的WEB框架,IRIS号称是Go最快的后端Web框架,目前发展最快的Go Web框架。提供完整的MVC功能并且面向未来。
所以先从它开始。

github地址
https://github.com/kataras/iris
文档
https://www.studyiris.com/doc/irisDoc/Installation.html

安装

go get -u github.com/kataras/iris

编辑main.go

package main

   import "github.com/kataras/iris"

   func main() {
     app := iris.Default()

     // Method:   GET
     // Resource: http://localhost:8080/
     app.Handle("GET", "/", func(ctx iris.Context) {
       ctx.HTML("Hello world!")
     })

     // same as app.Handle("GET", "/ping", [...])
     // Method:   GET
     // Resource: http://localhost:8080/ping
     app.Get("/ping", func(ctx iris.Context) {
       ctx.WriteString("pong")
     })

     // Method:   GET
     // Resource: http://localhost:8080/hello
     app.Get("/hello", func(ctx iris.Context) {
       ctx.JSON(iris.Map{"message": "Hello iris web framework."})
     })

     // http://localhost:8080
     // http://localhost:8080/ping
     // http://localhost:8080/hello
     app.Run(iris.Addr(":8080"))
   }

运行

go run main.go

新打开个窗口执行 
curl http://localhost:8080 
结果 Hello world! 
或在浏览器 访问http://localhost:8080

测试 
现在对它进行简单压力测试 
系统配置 1核 1G内存 , 操作系统:CentOS 7.4 64位

ab -n 10000 -c 1000 http://localhost:8080/
#结果
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        
Server Hostname:        localhost
Server Port:            8080

Document Path:          /
Document Length:        12 bytes

Concurrency Level:      1000
Time taken for tests:   3.102 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      1280000 bytes
HTML transferred:       120000 bytes
Requests per second:    3223.45 [#/sec] (mean)
Time per request:       310.227 [ms] (mean)
Time per request:       0.310 [ms] (mean, across all concurrent requests)
Transfer rate:          402.93 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  168 383.5      2    3013
Processing:     8  138 325.4     23    2005
Waiting:        1  137 325.5     22    2002
Total:          8  306 625.5     26    3067

Percentage of the requests served within a certain time (ms)
  50%     26
  66%     34
  75%     59
  80%     90
  90%   1480
  95%   1748
  98%   1925
  99%   3014
 100%   3067 (longest request)

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Go-Web框架-Beego架构(二)发布时间:2022-07-10
下一篇:
六款最棒的 Go 语言 Web 框架简介发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap