Skip to content

Instantly share code, notes, and snippets.

@mattn
Created April 19, 2016 16:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattn/af4afc6b3b6584e72c0dd43df87b83e1 to your computer and use it in GitHub Desktop.
Save mattn/af4afc6b3b6584e72c0dd43df87b83e1 to your computer and use it in GitHub Desktop.
package main
import (
"net/http"
"time"
"github.com/labstack/echo"
mw "github.com/labstack/echo/middleware"
)
// 現在時刻を取得
func getNow() string {
var loc, _ = time.LoadLocation("Asia/Tokyo")
var now = time.Now().In(loc).Format("2006-01-02 15:04:05")
return now
}
// Handler
func hello(c *echo.Context) error {
var content struct {
Response string `json:"response"`
Timestamp string `json:"timestamp"`
}
content.Response = "Hello, World!"
content.Timestamp = getNow()
return c.JSON(http.StatusOK, &content)
}
func main() {
// Echo instance
e := echo.New()
// Middleware
e.Use(mw.Logger())
e.Use(mw.Recover())
// Routes
e.Get("/", hello)
// Start server
e.Run(":1323")
}
package main
import (
"net/http"
"time"
"github.com/labstack/echo"
mw "github.com/labstack/echo/middleware"
)
var loc *time.Location
func init() {
loc, _ = time.LoadLocation("Asia/Tokyo")
}
// 現在時刻を取得
func getNow() string {
var now = time.Now().In(loc).Format("2006-01-02 15:04:05")
return now
}
// Handler
func hello(c *echo.Context) error {
var content struct {
Response string `json:"response"`
Timestamp string `json:"timestamp"`
}
content.Response = "Hello, World!"
content.Timestamp = getNow()
return c.JSON(http.StatusOK, &content)
}
func main() {
// Echo instance
e := echo.New()
// Middleware
e.Use(mw.Logger())
e.Use(mw.Recover())
// Routes
e.Get("/", hello)
// Start server
e.Run(":1323")
}
@mattn
Copy link
Author

mattn commented Apr 19, 2016

benchmark

time1

c:\dev\go-sandbox>ab -c 10 -n 10000 -k http://localhost:1323/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
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)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:
Server Hostname:        localhost
Server Port:            1323

Document Path:          /
Document Length:        62 bytes

Concurrency Level:      10
Time taken for tests:   1.172 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    10000
Total transferred:      2090000 bytes
HTML transferred:       620000 bytes
Requests per second:    8533.58 [#/sec] (mean)
Time per request:       1.172 [ms] (mean)
Time per request:       0.117 [ms] (mean, across all concurrent requests)
Transfer rate:          1741.72 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:     0    1   4.2      0      33
Waiting:        0    1   4.2      0      33
Total:          0    1   4.2      0      33

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      0
  90%      1
  95%     16
  98%     16
  99%     17
 100%     33 (longest request)

time2

c:\dev\go-sandbox>ab -c 10 -n 10000 -k http://localhost:1323/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
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)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:
Server Hostname:        localhost
Server Port:            1323

Document Path:          /
Document Length:        62 bytes

Concurrency Level:      10
Time taken for tests:   0.347 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    10000
Total transferred:      2090000 bytes
HTML transferred:       620000 bytes
Requests per second:    28789.99 [#/sec] (mean)
Time per request:       0.347 [ms] (mean)
Time per request:       0.035 [ms] (mean, across all concurrent requests)
Transfer rate:          5876.08 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     0    0   2.6      0      33
Waiting:        0    0   2.6      0      33
Total:          0    0   2.6      0      33

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      0
  90%      0
  95%      0
  98%      1
  99%     16
 100%     33 (longest request)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment