-
Notifications
You must be signed in to change notification settings - Fork 25
Closed
Description
Hi, I'm still researching this so it's a work-in-progress but I have narrowed it down enough that I thought it worthy of discussion. I've been using #30 in a pre-production project and I noticed some bottlenecks in parallel code. I started to research and I narrowed it down to WrapObject creating blocking-like behavior.
In a real-world project with hundreds of parallel tasks, I was noticing 200-500ms times in wrapping simple objects.
I narrowed it down to https://github.com/ipfs/go-ipld-cbor/blob/refmt/node.go#L184 but haven't yet found the root cause.
The rest of that function does not cause long blocking behavior.
Here's a failing test:
type testEncodeStruct struct {
Id string
Number int
}
func TestParallelWrap(t *testing.T) {
cbornode.RegisterCborType(testEncodeStruct{})
times := 10000
obj := &testEncodeStruct{Id: "test", Number: 100}
responses := make(chan int, times)
for i := 0; i < times; i++ {
go func() {
now := time.Now()
node,err := cbornode.WrapObject(obj, multihash.SHA2_256, -1)
end := int(time.Now().Sub(now))
assert.Nil(t, err)
assert.Len(t, node.RawData(), 18)
responses <- end
}()
}
respSlice := make([]int, times)
for i := 0; i < times; i++ {
respSlice[i] = <-responses
}
t.Logf("max was: %v", max(respSlice))
assert.True(t, max(respSlice)< int(100 * time.Millisecond))
}Metadata
Metadata
Assignees
Labels
No labels