seastar与go的http性能差异

golang的coroutine好用,但是coroutine本身切换是需要有代价的,主要体现在内存栈的上下文切换。之前看过一个C++的go风格的库,叫libgo, 根据其github主页的benchmark,协程切换速率是要优于go的。但是这篇文章并非要和libgo比较,由于笔者之前接触过scylladb,对seastar这个c++框架念念不忘,下面就来对比一下两者差异

OS:Ubuntu 18.04
go: 1.12
seastar: 18.08 (非dpdk模式)https://github.com/miaomiao3/seastar (从seastar fork出来的可以编译通过的分支)
wrk: 4,1,0
CPU: Ryzen 1700 8core 16 thread
Mem: 16GB 2400MHz

http server单线程模式

  • wrk 命令 wrk -t1 -c30 -d10 http://localhost:10000/
    -t 用于指定线程数
    -c 用于指定并发连接数

seastar: 使用例程apps/httpd, 指定-c 1参数
golang 测试代码:

package main

import (
	"fmt"
	"github.com/julienschmidt/httprouter"
	"log"
	"net/http"
	"runtime"
)

func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	fmt.Fprint(w, "Welcome!\n")
}
func main() {
	router := httprouter.New()
	runtime.GOMAXPROCS(1)
	router.GET("/", Index)

	log.Fatal(http.ListenAndServe(":8082", router))
}

下面是qps比较:

wrk 并发连接3050100
seastar 1thread105716107852110265
golang 1thread551065523553679

http server 2线程模式

  • wrk 命令 wrk -t1 -c30 -d10 http://localhost:10000/
    -t 用于指定线程数
    -c 用于指定并发连接数

seastar: 使用例程apps/httpd, 指定-c 2参数
golang 测试代码:

package main

import (
	"fmt"
	"github.com/julienschmidt/httprouter"
	"log"
	"net/http"
	"runtime"
)

func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	fmt.Fprint(w, "Welcome!\n")
}
func main() {
	router := httprouter.New()
	runtime.GOMAXPROCS(2)
	router.GET("/", Index)

	log.Fatal(http.ListenAndServe(":8082", router))
}

下面是qps比较:

wrk 并发连接3050100
seastar 2thread167313170687171913
golang 2thread925299543692773

小结

上面只是一个简单的测试,足以看到seastar的威力,性能接近go的两倍。对于http api服务,seastar的性能基本无敌,所以阿里的x-deeplearning推荐框架用了seastar来做参数服务器的后端框架(ps: 但是x-deeplearning用的blaze推理后端框架是libevent, 这操作就有点昏了~~)但是开发效率不如go。go的性能虽然稍微差一点,但是胜在开发效率优于c++。由于实际开发的时候,网络栈的处理延时远小于rpc/dbquery的等待时间,从实用的角度来看,go其实还是很棒的。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值