Skip to content

Bug fixing #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion echo_client
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ if __name__ == '__main__':
for fut in res.done:
t_messages, t_latency_stats, t_min_latency, t_max_latency = \
fut.result()
messages += t_messages
messages += t_messages * args.mpr
if latency_stats is None:
latency_stats = t_latency_stats
else:
Expand Down
44 changes: 35 additions & 9 deletions http_client
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ function done(summary, latency, requests)
"latency_percentiles": [%s]
}]]

transfer = (summary.bytes / (1024 * 1024)) / (summary.duration / 1000000)
rps = summary.requests / (summary.duration / 1000000)
transfer = 1024 * 1024 * 1024 * 1024 * 1024
rps = transfer
if summary.duration >= 1000 then
transfer = (summary.bytes / (1024 * 1024)) / (summary.duration / 1000000)
rps = summary.requests / (summary.duration / 1000000)
end
latency_percentiles = {}
percentiles = {25, 50, 75, 90, 99, 99.99}

Expand All @@ -41,11 +45,20 @@ function done(summary, latency, requests)
latency:percentile(percentile) / 1000)
)
end

out = string.format(tpl, summary.requests, transfer, rps,
latency.min / 1000, latency.mean / 1000,
latency.max / 1000, latency.stdev / 1000,
(latency.stdev / latency.mean) * 100,

latency_cv = 0
if latency.mean > 0.001 then
latency_cv = (latency.stdev / latency.mean) * 100
end

out = string.format(tpl,
summary.requests,
transfer, rps,
latency.min / 1000,
latency.mean / 1000,
latency.max / 1000,
latency.stdev / 1000,
latency_cv,
table.concat(latency_percentiles, ','))

io.stderr:write(out)
Expand Down Expand Up @@ -74,24 +87,37 @@ if __name__ == '__main__':
with tempfile.NamedTemporaryFile(mode='w+t', delete=False) as luaf:
luaf.write(luascript)
lua_script_path = luaf.name

wrk = ['wrk', '--latency', '--duration={}s'.format(args.duration),
'--connections={}'.format(args.concurrency),
'--script={}'.format(lua_script_path),
'http://{}/{}'.format(args.addr, args.msize)]

if 1 == args.concurrency:
wrk.append('--threads=1')

out = None
data_json = None
try:
wrk_run = subprocess.Popen(wrk, universal_newlines=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, data_json = wrk_run.communicate()
finally:
os.unlink(lua_script_path)

if data_json is not None:
data_json.replace('nan,', '0,')

if args.output_format == 'json':
print(data_json)
else:
data = json.loads(data_json)
try:
data = json.loads(data_json)
except ValueError:
print('Wrk Out:', out, ';\nWrk Err:', data_json)
raise


data['latency_percentiles'] = '; '.join(
'{}% under {}ms'.format(*v) for v in data['latency_percentiles'])
Expand Down
5 changes: 4 additions & 1 deletion servers/asyncio_http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ def __init__(self, *, loop=None):
self._current_headers = None

def on_url(self, url):
self._current_url = url
if self._current_url:
self._current_url += url
else:
self._current_url = url

def on_header(self, name, value):
self._current_headers.append((name, value))
Expand Down
44 changes: 42 additions & 2 deletions servers/goecho.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
const PORT = 25000

func main() {
fmt.Printf("Started\n")
server, err := net.Listen("tcp", ":"+strconv.Itoa(PORT))
if server == nil {
panic("couldn't start listening: " + err.Error())
Expand All @@ -28,16 +29,55 @@ func main() {
}
}

//func handleConn(client net.Conn) {
// // USELES RAW COPYLESS (ORIGINAL VERSION)
// defer client.Close()
// buf := make([]byte, 102400)
// for {
// reqLen, err := client.Read(buf)
// if err != nil {
// break
// }
// if reqLen > 0 {
// client.Write(buf[:reqLen])
// }
// }
//}

//func handleConn(client net.Conn) {
// // COPY FROM BUFF
// defer client.Close()
// buf := make([]byte, 102400)
// for {
// reqLen, err := client.Read(buf)
// resultBuf := make([]byte, reqLen)
// copy(resultBuf, buf)
// if err != nil {
// break
// }
// if reqLen > 0 {
// //client.Write(buf[:reqLen])
// client.Write(resultBuf)
// }
// }
//}

func handleConn(client net.Conn) {
// WITH SLICES
defer client.Close()
buf := make([]byte, 102400)
buf := make([]byte, 1048576)
for {
reqLen, err := client.Read(buf)
resultBuf := buf[:reqLen]
buf = buf[reqLen:]
if len(buf) <= 0 {
buf = make([]byte, 1048576)
}
if err != nil {
break
}
if reqLen > 0 {
client.Write(buf[:reqLen])
client.Write(resultBuf)
}
}
}