This is the 6th day of my participation in the More text challenge. More text Challenge this article has participated in the weekend learning plan, click the link to view the details: juejin.cn/post/696572…

If ❤️ my article is helpful, welcome to like, follow. This is the biggest encouragement for me to continue my technical creation.

This paper is: IRIS performance tests based on AB or WRK and subsequent performance optimization records of iris practice projects

Benchmarks: Requests/ SEC: 779.06 – QPS – Number of Requests per second

Compare operating performance before and after

  • Comparison 1: Whether the template supports each update check
  • Comparison 2: Enabling XORM data caching
  • Contrast 3: No template, no data
  • Contrast 4: Disable DEBUG logs

Comparison 1: Whether the template supports each update check

main3.go

TMPL := ir.html ("./web/views", ".html").layout ("shared/layout.html").reload (true) // The template will be reloaded each timeCopy the code

Set Reload to false. No longer does every request load disk related operations in the new template

$ wrk -c10 -t10 -d5 http://localhost:8080/index Running 5s test @ http://localhost:8080/index 10 threads and 10 Connections Thread Stats Avg Stdev Max +/- Stdev Latency 2.83ms 2.46ms 38.28ms 91.24% Req/Sec 398.03 66.54 570.00 68.20% 19836 requests in 5.01s, 94.91MB read requests/SEC: 3960.96 +3200 - QPS - Transfer/ SEC: 18.95MBCopy the code

Comparison 2: Enabling XORM data caching

datasource/dbhelper.go

"Xorm. IO /xorm/caches" Along with the native SQL cache cacher: = caches. NewLRUCacher (caches. NewMemoryStore (), 1000) masterEngine. SetDefaultCacher (cacher)Copy the code

thecacherSQL cache data open

$ wrk -c10 -t10 -d5 http://localhost:8080/index Running 5s test @ http://localhost:8080/index 10 threads and 10 Connections Thread Stats Avg Stdev Max +/- Stdev Latency 11.20ms 826.21us 18.13ms 79.28%req /Sec 89.30 4.82 101.00 Read requests/SEC: 890.51 +120 - QPS - Transfer requests/SEC: 4.26MBCopy the code

But if both the template cache and the data cache are turned on, the QPS jumps to a whopping 9172.56

$ wrk -c10 -t10 -d5 http://localhost:8080/index Running 5s test @ http://localhost:8080/index 10 threads and 10 Connections Thread Stats Avg Stdev Max +/- Stdev Latency 1.15ms 816.68us 9.77ms 78.78% Req/Sec 0.94k 171.16 4.39k 97.60% 46783 requests in 5.10s, 223.83MB Read requests/SEC: 9172.56 Transfer/ SEC: 43.89MBCopy the code

Contrast 3: No template, no data

web/controllers/index.go

func (c *IndexController) Get() mvc.Result { return mvc.Response{ Text: "ok \n", } //datalist := c.Service.GetAll() //return mvc.View{ // Name: "index.html", // Data: iris.Map{ // "Title": // "Datalist": Datalist, //}, //}}Copy the code

Returns directly without checking data

$ wrk -c10 -t10 -d5 http://localhost:8080/index Running 5s test @ http://localhost:8080/index 10 threads and 10 Connections Thread Stats Avg Stdev Max +/- Stdev Latency 333.19us 630.26us 13.84ms 94.94% Req/Sec 4.41k 411.91 6.18k 72.44% 222678 requests in 5.10s, 25.48MB read requests/SEC: 43660.91 Transfer/ SEC: 5.00MBCopy the code

Contrast 4: Disable DEBUG logs

Annotation web/main3. Go

app.Logger().SetLevel("debug")
Copy the code

Comment out, do not log on the command line, improved by 130 +

$ wrk -c10 -t10 -d5 http://localhost:8080/index Running 5s test @ http://localhost:8080/index 10 threads and 10 Connections Thread Stats Avg Stdev Max +/- Stdev Latency 333.11us 648.99us 13.47ms 69.80% 229472 requests in 5.10s, 26.26MB read requests/SEC: 44967.99 Transfer/ SEC: 5.15MBCopy the code

conclusion

In common development computers, Golang can gradually increase data cache and template cache, and even double. Effect is good