-
Notifications
You must be signed in to change notification settings - Fork 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
add benchmark test #62
base: main
Are you sure you want to change the base?
Conversation
tracelistener/benchmark_test.go
Outdated
if err != nil { | ||
return err | ||
} | ||
trace := tracelistener.TraceOperation{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cannot use this object to marshal trace operations, you must use the (non-exported) traceOperationInter
object.
This one is just a high-level representation of a trace, not the wire-level format the chain outputs.
Also, what key/value are you sending? What's the aim of this benchmark? Speed of processing or just ingestion speed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are just checking ingestion speed and not considering processing speed.
tracelistener/benchmark_test.go
Outdated
Operation: string(tracelistener.WriteOp), | ||
Key: []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f, 0xa}, | ||
Value: []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f, 0xa}, | ||
BlockHeight: uint64(height), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving the same block height for all traces will never trigger a database write, since tracelistener will only write back to database when the block height changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am passing blockheight from benchmark function which will be dynamic and different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right! 👯
tracelistener/benchmark_test.go
Outdated
} | ||
} | ||
|
||
func loadTest(height int, file string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func loadTest(height int, file string) error { | |
func loadTest(b *testing.B, height int, file string) error { | |
b.Helper() |
This function should be marked as helper, so that it gets ignored in performance counting.
tracelistener/benchmark_test.go
Outdated
} | ||
|
||
func loadTest(height int, file string) error { | ||
ff, err := fifo.OpenFifo(context.Background(), file, syscall.O_WRONLY, 0655) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not open and close the FIFO, just open it at the beginning of the test and close it when done.
This way it resembles more how real execution behaves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even just doing this improves dramatically the performance of the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I tried with opening file only once in the beginning. But, tracelistener is considering all traces into one single trace and just parsing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please check these logs
Fifo opening and closing each time: https://pastebin.com/22SSVnaq
Fifo opening only once in beginning; https://pastebin.com/RQjeRXSg
When fifo is opened in the beginning, new trace is being appended to previous trace everytime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use fmt.Fprintf
instead of writing directly, and append a newline at the end of each serialized trace.
@@ -56,6 +57,11 @@ $(TEST_VERSIONS): | |||
go test -v -failfast -race -count=1 \ | |||
-tags $(shell echo $@ | sed -e 's/test-/sdk_/g' -e 's/-/_/g'),muslc \ | |||
./... | |||
|
|||
$(BENCHMARK_VERSIONS): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be useful to enable CPU and memory profiling while running benchmarks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am not wrong, -benchmem
flag will give you the same right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to supply flags like those as well to create the profiling files:
-cpuprofile=cpu.out -memprofile=mem.out -trace=trace.out
Hmm I got wildly different numbers. The estimated execution time calculated by
So for 10M traces processed, I have a runtime of about 41s. I ran those tests on an ARM M1 Pro machine. |
From a quick test, looks like the json.Marshal method is actually bottlenecking the whole thing... Incredible :| |
Initially, I did load testing on tracelistener with multiple traces and here are the stats:
After that, I tried to do benchmarking testing and here is the result of it:
Please run
make benchmark-<sdk-version>
to run benchmark test locally