{"action":"created","issue":{"url":"https://api.github.com/repos/shixinke/lua-resty-ip2region/issues/5","repository_url":"https://api.github.com/repos/shixinke/lua-resty-ip2region","labels_url":"https://api.github.com/repos/shixinke/lua-resty-ip2region/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/shixinke/lua-resty-ip2region/issues/5/comments","events_url":"https://api.github.com/repos/shixinke/lua-resty-ip2region/issues/5/events","html_url":"https://github.com/shixinke/lua-resty-ip2region/issues/5","id":342589514,"node_id":"MDU6SXNzdWUzNDI1ODk1MTQ=","number":5,"title":"golang vs openresty","user":{"login":"wzhsh90","id":16187191,"node_id":"MDQ6VXNlcjE2MTg3MTkx","avatar_url":"https://avatars3.githubusercontent.com/u/16187191?v=4","gravatar_id":"","url":"https://api.github.com/users/wzhsh90","html_url":"https://github.com/wzhsh90","followers_url":"https://api.github.com/users/wzhsh90/followers","following_url":"https://api.github.com/users/wzhsh90/following{/other_user}","gists_url":"https://api.github.com/users/wzhsh90/gists{/gist_id}","starred_url":"https://api.github.com/users/wzhsh90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wzhsh90/subscriptions","organizations_url":"https://api.github.com/users/wzhsh90/orgs","repos_url":"https://api.github.com/users/wzhsh90/repos","events_url":"https://api.github.com/users/wzhsh90/events{/privacy}","received_events_url":"https://api.github.com/users/wzhsh90/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-19T06:02:33Z","updated_at":"2018-07-19T07:03:36Z","closed_at":"2018-07-19T07:03:36Z","author_association":"NONE","body":"method: BtreeSearch ip:125.81.12.166\r\n\r\ntest method: ab -c 1000 -n 10000 http://localhost:8080/wx/account/ip \r\n\r\n1、this is my golang test result\r\n![image](https://user-images.githubusercontent.com/16187191/42924240-d9217b36-8b5b-11e8-848e-d706a1872663.png)\r\n\r\n2、this is my openresty test result \r\n\r\n![image](https://user-images.githubusercontent.com/16187191/42924323-354a0b1c-8b5c-11e8-938e-769fc70c0a50.png)\r\n\r\n golang works better than openresty \r\n\r\n"},"comment":{"url":"https://api.github.com/repos/shixinke/lua-resty-ip2region/issues/comments/406176004","html_url":"https://github.com/shixinke/lua-resty-ip2region/issues/5#issuecomment-406176004","issue_url":"https://api.github.com/repos/shixinke/lua-resty-ip2region/issues/5","id":406176004,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNjE3NjAwNA==","user":{"login":"shixinke","id":9602010,"node_id":"MDQ6VXNlcjk2MDIwMTA=","avatar_url":"https://avatars1.githubusercontent.com/u/9602010?v=4","gravatar_id":"","url":"https://api.github.com/users/shixinke","html_url":"https://github.com/shixinke","followers_url":"https://api.github.com/users/shixinke/followers","following_url":"https://api.github.com/users/shixinke/following{/other_user}","gists_url":"https://api.github.com/users/shixinke/gists{/gist_id}","starred_url":"https://api.github.com/users/shixinke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shixinke/subscriptions","organizations_url":"https://api.github.com/users/shixinke/orgs","repos_url":"https://api.github.com/users/shixinke/repos","events_url":"https://api.github.com/users/shixinke/events{/privacy}","received_events_url":"https://api.github.com/users/shixinke/received_events","type":"User","site_admin":false},"created_at":"2018-07-19T07:03:36Z","updated_at":"2018-07-19T07:03:36Z","author_association":"OWNER","body":"Thank you for your attention and message.\r\nThis library contains a lot of IO operations and CPU calculations.In a production environment, the configuration option of lua_code_cache  needs to be set to on.The following is my test results:\r\n\r\nMy stress test tool is **wrk**.\r\n\r\n#### Golang\r\n\r\ngolang demo code:\r\n\r\n```\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"net/http\"\r\n\r\n\t\"github.com/mohong122/ip2region/binding/golang/ip2region\"\r\n)\r\n\r\nfunc handler(w http.ResponseWriter, r *http.Request) {\r\n\tregion, err := ip2region.New(\"src/github.com/mohong122/ip2region/data/ip2region.db\")\r\n\tdefer region.Close()\r\n\tif err != nil {\r\n\t\tfmt.Println(err)\r\n\t\treturn\r\n\t}\r\n\r\n\tip, err := region.BtreeSearch(\"125.81.12.166\")\r\n\tif err != nil {\r\n\t\tw.Write([]byte(\"not found\"))\r\n\t} else {\r\n\t\tvar resp string = \"\"\r\n\t\tresp = ip.Country + \" \" + ip.Region + \" \" + ip.Province + \" \"+ip.City + \" \"+ ip.ISP\r\n\t\tw.Write([]byte(resp))\r\n\t}\r\n\r\n}\r\n\r\nfunc main() {\r\n\thttp.HandleFunc(\"/iplocation\", handler)\r\n\terr := http.ListenAndServe(\":8888\", nil)\r\n\tif err != nil {\r\n\t\tfmt.Printf(\"http error:%v\", err)\r\n\t}\r\n\r\n}\r\n```\r\n\r\nI am using a standard library instead of a beego framework.\r\n\r\n```\r\nwrk -c 10000 -t 10 -d 30s http://localhost:8888/iplocation --timeout 30s\r\n```\r\n\r\ngolang result:\r\n\r\n```\r\nRunning 30s test @ http://localhost:8888/iplocation\r\n  10 threads and 10000 connections\r\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\r\n    Latency    16.57ms   20.40ms 251.58ms   87.05%\r\n    Req/Sec     6.81k     3.24k   13.80k    60.37%\r\n  1828965 requests in 30.04s, 273.85MB read\r\n  Socket errors: connect 8989, read 0, write 0, timeout 0\r\nRequests/sec:  60879.19\r\nTransfer/sec:      9.12MB\r\n\r\n```\r\n\r\n#### OpenResty\r\n\r\n1.When nginx's configuration option worker_process is set to 1, the result is as follows:\r\n\r\nwrk -c 10000 -t 10 -d 30s http://localhost/iplocation --timeout 30s\r\n\r\n\r\n```Running 30s test @ http://localhost/iplocation\r\n  10 threads and 10000 connections\r\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\r\n    Latency    40.12ms  307.92ms  17.43s    99.15%\r\n    Req/Sec     2.06k     1.09k    6.13k    63.82%\r\n  576220 requests in 30.10s, 131.31MB read\r\n  Socket errors: connect 0, read 2972, write 0, timeout 0\r\nRequests/sec:  19145.30\r\nTransfer/sec:      4.36MB\r\n```\r\n\r\n2.When nginx's configuration option worker_process is set to 8(My computer has 8 processor), the result is as follows:\r\n\r\n```\r\nRunning 30s test @ http://localhost/iplocation\r\n  10 threads and 10000 connections\r\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\r\n    Latency    40.54ms  137.43ms  28.63s    99.17%\r\n    Req/Sec     7.20k     2.14k   35.41k    68.55%\r\n  2138083 requests in 30.10s, 487.23MB read\r\n  Socket errors: connect 0, read 2375, write 0, timeout 0\r\nRequests/sec:  71032.20\r\nTransfer/sec:     16.19MB\r\n\r\n```\r\n\r\nTherefore, it doesn't make sense to say what language performance is good. It depends on the context, which language is more suitable.\r\n"}}
{"actor":{"display_login":"shixinke"}}