Skip to content

Instantly share code, notes, and snippets.

@caleblloyd
Last active October 22, 2016 04:39
Show Gist options
  • Save caleblloyd/188a13673388ed45e68b8c9e8fd93dae to your computer and use it in GitHub Desktop.
Save caleblloyd/188a13673388ed45e68b8c9e8fd93dae to your computer and use it in GitHub Desktop.
./stress.sh 3000 1s async2
Rate = 3000 RPS
Duration = 1s
Targets = targets-async2.txt
Requests [total, rate] 3000, 3001.00
Duration [total, attack, wait] 1.000210473s, 999.66543ms, 545.043µs
Latencies [mean, 50, 95, 99, max] 10.404817ms, 448.391µs, 70.46273ms, 115.09937ms, 139.388358ms
Bytes In [total, mean] 45288000, 15096.00
Bytes Out [total, mean] 0, 0.00
Success [ratio] 100.00%
Status Codes [code:count] 200:3000
package main
import (
"database/sql"
"log"
"net/http"
"strconv"
"github.com/go-ozzo/ozzo-routing"
"github.com/go-ozzo/ozzo-routing/access"
"github.com/go-ozzo/ozzo-routing/slash"
"github.com/go-ozzo/ozzo-routing/content"
"github.com/go-ozzo/ozzo-routing/fault"
_ "github.com/go-sql-driver/mysql"
)
func main(){
db, err := sql.Open("mysql", "root:test@tcp(127.0.0.1:3306)/mysqltest")
if err != nil {
log.Fatal(err)
}
db.SetMaxOpenConns(100);
router := routing.New()
router.Use(
// all these handlers are shared by every route
access.Logger(log.Printf),
slash.Remover(http.StatusMovedPermanently),
fault.Recovery(log.Printf),
)
api := router.Group("/api")
api.Use(
content.TypeNegotiator(content.JSON),
)
api.Get("/async", func(c *routing.Context) error {
var (
Id int
Title string
Content string
)
stmt, err := db.Prepare("SELECT `Id`, `Title`, `Content` FROM `BlogPost` ORDER BY `Id` DESC LIMIT 10;")
if err != nil {
log.Fatal(err)
}
defer stmt.Close()
rows, err := stmt.Query()
defer rows.Close()
c.Write("[")
for rows.Next() {
err := rows.Scan(&Id, &Title, &Content)
if err != nil {
log.Fatal(err)
}
c.Write("{ \"Id\":\"" + strconv.Itoa(Id) +
"\", \"Title\": \"" + Title +
"\", \"Content\": \"" + Content +
"\"}")
}
c.Write("]")
if err = rows.Err(); err != nil {
log.Fatal(err)
}
return nil
})
http.Handle("/", router)
http.ListenAndServe(":5000", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment