测试用API基准性能测试
 
  API编写
 
 为了测试API Gateway的性能,我们首先要有一个测试用API。 用Go语言,采用基于fasthttp的iris框架,编写一个简单的HelloWorld Server。如下所示:
 
  
 package mainimport "github.com/kataras/iris"func main() { api := iris.New() api.Get("/hi", hi) api.Listen(":8080")}func hi(ctx *iris.Context){ ctx.Write("Hi %s", "iris")}
  测试API是否可用
 
  
 $ curl http://127.0.0.1:8080/hiHi iris
  Bench测试用API
 
  
 并发 RPS TPR1 21391.66 0.0472 29864.03 0.0673 63258.51 0.0474 73325.61 0.0555 80241.88 0.0628 99025.29 0.08110 105148.38 0.09516 99378.09 0.16120 99064.04 0.20225 96601.46 0.25930 94350.84 0.31832 97307.03 0.32940 93983.53 0.42650 95480.85 0.52464 94770.72 0.67580 90437.65 0.885100 93304.23 1.072120 91837.84 1.307128 91585.78 1.398150 92307.99 1.625180 92827.5 1.939200 93157.63 2.147500 93920.95 5.3241000 90560.25 11.0422000 73470.44 27.2225000 72345.1 69.11310000 70525.77 141.792
 结论是,在合理的并发数下,QPS基本可以稳定在9W左右。最佳并发数为10。 对于测试,该API不可能成为瓶颈。
 
  单实例API网关
 
  注册为OpenAPI
 
  
 curl -X POST http://localhost:8888/apis/ \-d "name=overseas_index" \-d "upstream_url=http://10.182.20.100:8080/" \-d "request_path=/test" \-d "strip_request_path=true"{"upstream_url":"http:\/\/10.182.20.100:8080\/","request_path":"\/test","id":"36cc77c7-89cd-49d3-b153-e79c632ccc44","created_at":1471509004000,"preserve_host":false,"strip_request_path":true,"name":"overseas_index"}
  测试OpenAPI连通情况
 
  
 $ curl http://127.0.0.1/test/hiHi iris
  从同机房通过API Gateway进行测试:
 
  
 c n rps tpr50 100000 13780.78 3.628100 100000 16499.59 6.061200 100000 15778.13 12.676500 100000 14109.51 35.437
  使用OpenAPI,添加key-auth权限认证,ACL,从外网接口访问:
 
  
 c n rps tpr50 100000 14006.29 3.570100 100000 16087.16 6.216200 100000 16033.10 12.474500 100000 14080.34 35.511
 (3 Nginx Node, 3x24 EchoServer)
 
 在没有进行任何优化的条件下,峰值约16000 QPS。应对目前Cplus需求非常充裕。但对于DMP还需要进一步优化。优化空间很大。
 
                
        
 
相关资源:开放平台的OpenAPI设计