Commit b062b349 authored by Kirill Smelkov's avatar Kirill Smelkov

X microbenchmark CPU first

parent f7e23ed8
...@@ -2,4 +2,6 @@ ...@@ -2,4 +2,6 @@
/var /var
/zhash /zhash
/zhash_go /zhash_go
/tsha1
/tsha1_go
/ioping.tmp /ioping.tmp
...@@ -600,8 +600,8 @@ cpustat() { ...@@ -600,8 +600,8 @@ cpustat() {
ustartv=( `statev_usage` ) ustartv=( `statev_usage` )
#echo >&2 "--------" #echo >&2 "--------"
#sleep 1 #sleep 1
out="$("$@" 2>&1)" ret=0
ret=$? out="$("$@" 2>&1)" || ret=$?
uendv=( `statev_usage` ) uendv=( `statev_usage` )
stat="#" stat="#"
...@@ -654,12 +654,22 @@ runpar() { ...@@ -654,12 +654,22 @@ runpar() {
$profile _runpar "$@" $profile _runpar "$@"
} }
# bench_disk - print disk identification and benchmark direct (uncached) and cached random reads # bench_cpu - microbenchmark CPU
bench_cpu() {
nrun sh -c "python -m test.pystone |tail -1"
nrun ./tsha1.py 1024
nrun ./tsha1_go 1024
nrun ./tsha1.py 4096
nrun ./tsha1_go 4096
}
# bench_disk - benchmark direct (uncached) and cached random reads
bench_disk() { bench_disk() {
echo -e "\n*** random direct (no kernel cache) 4K-read disk latency" echo -e "\n*** disk: random direct (no kernel cache) 4K-read latency"
nrun ioping -D -i 0ms -s 4k -S 1024M -w 3s -q -k . nrun ioping -D -i 0ms -s 4k -S 1024M -w 3s -q -k .
echo -e "\n*** random cached 4K-read disk latency" echo -e "\n*** disk: random cached 4K-read latency"
# warmup so kernel puts the file into pagecache # warmup so kernel puts the file into pagecache
for i in `seq 3`; do for i in `seq 3`; do
cat ioping.tmp >/dev/null cat ioping.tmp >/dev/null
...@@ -709,6 +719,8 @@ bench_go() { ...@@ -709,6 +719,8 @@ bench_go() {
cmd_bench-local() { cmd_bench-local() {
echo -e ">>> bench-local" echo -e ">>> bench-local"
system_info system_info
echo -e "\n*** cpu:\n"
bench_cpu
bench_disk bench_disk
install_trap install_trap
gen_data gen_data
...@@ -763,6 +775,12 @@ cmd_bench-cluster() { ...@@ -763,6 +775,12 @@ cmd_bench-cluster() {
echo -e "\n# client:" echo -e "\n# client:"
on $url ./neotest info-local on $url ./neotest info-local
echo -e "\n*** server cpu:"
bench_cpu
echo -e "\n*** client cpu:"
on $url ./neotest bench-cpu
echo -e "\n*** server disk:" echo -e "\n*** server disk:"
bench_disk bench_disk
...@@ -862,6 +880,16 @@ cmd_run-client() { ...@@ -862,6 +880,16 @@ cmd_run-client() {
test -z "$goonly" && bench $url || bench_go $url test -z "$goonly" && bench $url || bench_go $url
} }
# command: benchmark local disk
cmd_bench-disk() {
bench_disk
}
# command: benchmark local cpu
cmd_bench-cpu() {
bench_cpu
}
# command: print information about local node # command: print information about local node
cmd_info-local() { cmd_info-local() {
init_net init_net
...@@ -891,6 +919,8 @@ The commands are: ...@@ -891,6 +919,8 @@ The commands are:
bench-cluster run benchmarks when server is local and client is on another node bench-cluster run benchmarks when server is local and client is on another node
run-client run client benchmarks against separate server run-client run client benchmarks against separate server
bench-disk benchmark local disk (already part of bench-{local,cluster})
bench-cpu benchmark local cpu (already part of bench-{local,cluster})
deploy deploy NEO & needed software for tests to remote host deploy deploy NEO & needed software for tests to remote host
deploy-local deploy NEO & needed software for tests locally deploy-local deploy NEO & needed software for tests locally
...@@ -903,8 +933,10 @@ EOF ...@@ -903,8 +933,10 @@ EOF
case "$1" in case "$1" in
# commands that require build # commands that require build
bench-local | \ bench-local | \
bench-cluster | \
run-client | \ run-client | \
bench-cluster) bench-disk | \
bench-cpu)
;; ;;
info) info)
...@@ -934,6 +966,7 @@ esac ...@@ -934,6 +966,7 @@ esac
# neo/py, wendelin.core, ... - must be pip install'ed - `neotest deploy` cares about that # neo/py, wendelin.core, ... - must be pip install'ed - `neotest deploy` cares about that
go install -v lab.nexedi.com/kirr/neo/go/... go install -v lab.nexedi.com/kirr/neo/go/...
go build -o zhash_go zhash.go go build -o zhash_go zhash.go
go build -o tsha1_go tsha1.go
# setup network & fs environment # setup network & fs environment
init_net init_net
......
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
// +build ignore
// tsha1 - benchmark sha1
package main
import (
"crypto/sha1"
"fmt"
"log"
"os"
"strconv"
"time"
)
func dieusage() {
fmt.Fprintf(os.Stderr, "Usage: tsha1 <block-size>\n")
os.Exit(1)
}
func main() {
if len(os.Args) != 2 {
dieusage()
}
blksize, err := strconv.Atoi(os.Args[1])
if err != nil {
log.Fatal(err)
}
data := make([]byte, blksize)
h := sha1.New()
n := int(1E6)
if blksize > 1024 {
n = n * 1024 / blksize // assumes 1K ~= 1μs
}
tstart := time.Now()
for i := 0; i < n; i++ {
h.Write(data)
}
tend := time.Now()
δt := tend.Sub(tstart)
fmt.Printf("sha1(%dB) ~= %s x=tsha1.go\n", blksize, δt / time.Duration(n))
}
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2017 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
"""tsha1 - benchmark sha1"""
from __future__ import print_function
import sys
import hashlib
from time import time
def main():
blksize = int(sys.argv[1])
data = '\0'*blksize
h = hashlib.sha1()
tstart = time()
n = int(1E6)
if blksize > 1024:
n = n * 1024 / blksize # assumes 1K ~= 1μs
i = 0
while i < n:
h.update(data)
i += 1
tend = time()
dt = tend - tstart
print('sha1(%dB) ~= %.1fμs x=tsha1.py' % (blksize, dt * 1E6 / n))
if __name__ == '__main__':
main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment