Last active
December 12, 2017 13:59
-
-
Save rburdet/6803dcad6a048b6becba1af921f79d31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/gin-gonic/gin" | |
"gopkg.in/resty.v1" | |
) | |
const url string = "localhost:6667" | |
func doRequests() { | |
for i := 0; i < 10; i++ { | |
resp, err := resty.R().Get(url) | |
if err != nil { | |
_ = resp | |
} | |
} | |
} | |
func main() { | |
r := gin.Default() | |
r.GET("/bench", func(c *gin.Context) { | |
doRequests() | |
c.JSON(200, gin.H{ | |
"message": "pong", | |
}) | |
}) | |
r.Run() // listen and serve on 0.0.0.0:8080 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ab -n 10000 -c 50 localhost:8080/bench > go_benchmark | |
This is ApacheBench, Version 2.3 <$Revision: 1796539 $> | |
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) | |
Server Software: | |
Server Hostname: localhost | |
Server Port: 8080 | |
Document Path: /bench | |
Document Length: 18 bytes | |
Concurrency Level: 50 | |
Time taken for tests: 1.856 seconds | |
Complete requests: 10000 | |
Failed requests: 0 | |
Total transferred: 1410000 bytes | |
HTML transferred: 180000 bytes | |
Requests per second: 5387.27 [#/sec] (mean) | |
Time per request: 9.281 [ms] (mean) | |
Time per request: 0.186 [ms] (mean, across all concurrent requests) | |
Transfer rate: 741.80 [Kbytes/sec] received | |
Connection Times (ms) | |
min mean[+/-sd] median max | |
Connect: 0 3 24.9 3 1021 | |
Processing: 0 6 9.7 4 140 | |
Waiting: 0 5 9.7 3 140 | |
Total: 1 9 26.8 7 1037 | |
Percentage of the requests served within a certain time (ms) | |
50% 7 | |
66% 8 | |
75% 8 | |
80% 9 | |
90% 10 | |
95% 14 | |
98% 26 | |
99% 28 | |
100% 1037 (longest request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const fetch = require('node-fetch'); | |
const app = express(); | |
const URL = "http://localhost:6667"; | |
const PORT = 6666; | |
const buildPromise = () => fetch(URL).then(data => data.json()) | |
const executeBench = () => { | |
const promises = [] | |
for (i = 0; i < 10 ; i++) { | |
promises.push(buildPromise()) | |
} | |
return Promise.all(promises) | |
} | |
app.get('/bench', (req, res) => { | |
executeBench() | |
.then(data => res.send(data)) | |
}) | |
app.listen(PORT, () => { | |
console.log("listening on port ", PORT); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = express(); | |
const PORT = 6667; | |
app.get('/', (req, res) => { | |
setTimeout( () => | |
res.json({rand:Math.random()}) | |
, 20) | |
}) | |
app.listen(PORT, () => { | |
console.log("listening on port ", PORT); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ab -n 10000 -c 50 localhost:6666/bench > benchmark | |
This is ApacheBench, Version 2.3 <$Revision: 1796539 $> | |
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) | |
Server Software: | |
Server Hostname: localhost | |
Server Port: 6666 | |
Document Path: /bench | |
Document Length: 144 bytes | |
Concurrency Level: 50 | |
Time taken for tests: 2.184 seconds | |
Complete requests: 10000 | |
Failed requests: 0 | |
Non-2xx responses: 10000 | |
Total transferred: 3880000 bytes | |
HTML transferred: 1440000 bytes | |
Requests per second: 4577.81 [#/sec] (mean) | |
Time per request: 10.922 [ms] (mean) | |
Time per request: 0.218 [ms] (mean, across all concurrent requests) | |
Transfer rate: 1734.56 [Kbytes/sec] received | |
Connection Times (ms) | |
min mean[+/-sd] median max | |
Connect: 0 0 0.1 0 3 | |
Processing: 1 11 9.4 10 144 | |
Waiting: 1 11 9.3 10 144 | |
Total: 3 11 9.4 10 144 | |
Percentage of the requests served within a certain time (ms) | |
50% 10 | |
66% 10 | |
75% 11 | |
80% 12 | |
90% 13 | |
95% 14 | |
98% 15 | |
99% 17 | |
100% 144 (longest request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "cocubench", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"express": "^4.16.2", | |
"node-fetch": "^1.7.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment