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

Performance is worse than terrible #277

Open
inv2004 opened this Issue Sep 23, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@inv2004
Copy link

inv2004 commented Sep 23, 2018

mongodb = "0.3.10"

rustc --version
rustc 1.30.0-nightly (4591a245c 2018-09-22)

mongod --version
db version v4.0.2

Rust:
https://gist.github.com/inv2004/87b49ee4217872d9260e13a09e6bf524

$ time ./target/release/bench_mongo
real    0m44.043s

Go:
https://gist.github.com/inv2004/d8e397ee7d0553940b60dff7f3005540

$ time ./bench_mongo
real    0m0.798s

---added---
mongo_driver:
real 0m0.583s

@vaffeine

This comment has been minimized.

Copy link

vaffeine commented Sep 23, 2018

I took a quick look at the problem with callgrind. The first thing that caught my eye was a huge amount of allocations caused by in bson::OrderedDocument::clone(), and then the same amount of deallocations, when OrderedDocument is dropped. In case of your gist OrderedDocument::clone() is called 9046, which results in 243000 calls to both __rust__alloc and __rust_dealloc at the bottom of the call stack.
I was not able to try the same thing with Go, but I believe it doesn't allocate and then immediately drop document for each insert.
The other thing is that Collection::insert() itself took only 16% of total execution time. However, Cursor::query() took 59%. I am pretty new to this library and MongoDB itself, so I don't know if it is normal.
Going to take a look at Go and PyMongo to makes the difference.

@inv2004

This comment has been minimized.

Copy link

inv2004 commented Sep 24, 2018

Thank you, its s good point, because mongo_driver uses doc by ref also. Unfortunately, I do not think that these allocations is the main point, because initial problem was found in the code, which generates uniq doc's.

Also, I did not make any special benchmarks, but I see that .find in mongo_driver is even much faster than mongodb. ~5k/1sec (native) vs ~15k/1sec (WSL)

@inv2004

This comment has been minimized.

Copy link

inv2004 commented Oct 17, 2018

Would you like me to do another test without allocation?

Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment