mirror of
https://github.com/aykhans/sarin.git
synced 2026-08-29 03:24:33 +00:00
Merge pull request #215 from aykhans/perf/remove-hot-path-contention
perf
This commit is contained in:
@@ -12,19 +12,19 @@ import (
|
|||||||
const dryRunResponseKey = "dry-run"
|
const dryRunResponseKey = "dry-run"
|
||||||
|
|
||||||
// statusCodeStrings contains pre-computed string representations for HTTP status codes 100-599.
|
// statusCodeStrings contains pre-computed string representations for HTTP status codes 100-599.
|
||||||
var statusCodeStrings = func() map[int]string {
|
var statusCodeStrings = func() [500]string {
|
||||||
m := make(map[int]string, 500)
|
var codes [500]string
|
||||||
for i := 100; i < 600; i++ {
|
for i := range codes {
|
||||||
m[i] = strconv.Itoa(i)
|
codes[i] = strconv.Itoa(i + 100)
|
||||||
}
|
}
|
||||||
return m
|
return codes
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// statusCodeToString returns a string representation of the HTTP status code.
|
// statusCodeToString returns a string representation of the HTTP status code.
|
||||||
// Uses a pre-computed map for codes 100-599, falls back to strconv.Itoa for others.
|
// Uses a pre-computed table for codes 100-599, falls back to strconv.Itoa for others.
|
||||||
func statusCodeToString(code int) string {
|
func statusCodeToString(code int) string {
|
||||||
if s, ok := statusCodeStrings[code]; ok {
|
if i := code - 100; i >= 0 && i < len(statusCodeStrings) {
|
||||||
return s
|
return statusCodeStrings[i]
|
||||||
}
|
}
|
||||||
return strconv.Itoa(code)
|
return strconv.Itoa(code)
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,6 @@ func (s sarin) workerStatsWithDynamic(
|
|||||||
) {
|
) {
|
||||||
for range jobs {
|
for range jobs {
|
||||||
req.Reset()
|
req.Reset()
|
||||||
resp.Reset()
|
|
||||||
|
|
||||||
if err := requestGenerator(req); err != nil {
|
if err := requestGenerator(req); err != nil {
|
||||||
s.responses.Add(err.Error(), 0)
|
s.responses.Add(err.Error(), 0)
|
||||||
@@ -138,8 +137,6 @@ func (s sarin) workerStatsWithStatic(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for range jobs {
|
for range jobs {
|
||||||
resp.Reset()
|
|
||||||
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
err := hostClientGenerator().DoTimeout(req, resp, s.timeout)
|
err := hostClientGenerator().DoTimeout(req, resp, s.timeout)
|
||||||
respDuration := time.Since(startTime)
|
respDuration := time.Since(startTime)
|
||||||
@@ -165,7 +162,6 @@ func (s sarin) workerNoStatsWithDynamic(
|
|||||||
) {
|
) {
|
||||||
for range jobs {
|
for range jobs {
|
||||||
req.Reset()
|
req.Reset()
|
||||||
resp.Reset()
|
|
||||||
if err := requestGenerator(req); err != nil {
|
if err := requestGenerator(req); err != nil {
|
||||||
sendLog(runtimeLogLevelError, err.Error())
|
sendLog(runtimeLogLevelError, err.Error())
|
||||||
counter.Add(1)
|
counter.Add(1)
|
||||||
@@ -201,7 +197,6 @@ func (s sarin) workerNoStatsWithStatic(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for range jobs {
|
for range jobs {
|
||||||
resp.Reset()
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
err := hostClientGenerator().DoTimeout(req, resp, s.timeout)
|
err := hostClientGenerator().DoTimeout(req, resp, s.timeout)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user