What the overhead of Java ORM for MongoDB

China☆狼群 提交于 2019-12-03 09:43:08

问题


What is the overhead of using Java ORM for MongoDB, or its better that we go the at basic driver level to read or write?

We will be adding Mongo DB for one of our requirements.

There are couple of java ORM mapping tools for java
-morphia
-spring-data
-others

Morphia last version was released more than a year ago
but Spring data is actively maintained. Which one should be used if I am about to start now,


回答1:


Using ORM decreases the performance but it speed up the development. There is a trade off here.

For ORM tools, Morphia is most stable one. Here you can find the comparison between the Morphia and Basic Mongo Driver by their performance.




回答2:


Morphia seems to be best suitable as it has the most features and have active community. See this link for comparison: How do Morphia, Mongo4j and Spring data for MongoDB compare?




回答3:


There's quite a few thing's to mention here in general. Coming up with benchmarks for that is quite hard as you cannot really test the performance without testing your MongoDB setup as well. Thus one can pretty much can tweak and tune ones environment to deliver the results wanted.

Beyond that you have to distinguish between read and write performance. Especially writes are heavily influenced by the WriteConcern used. Thus, what might be an overhead of 50% in a WriteConcern.NONE scenario can easily turn down to less than 5% with a WriteConcern.SAFE.

Yes, there definitely is an overhead in any ODM implementation as the Object <-> DBObject mapping has to inspect the object get and set values usually via reflection. Thus a crucial point IMHO is the ability to plug in custom manually coded converters that you might want to provide for the performance critical objects. For Spring Data simply registering a custom EntityInstantiator that does new Person(…) instead of letting the default one do its reflection magic gives a huge boost in performance.

The Spring Data team has a build set up a build weighting performance of a OTS MongoDB instance for writes against different WriteConcerns, and reading through the plain driver, the MongoTemplate and the repositories abstraction. The numbers are to be taken with a grain of salt as they sometimes show the repositories reading data faster than the templates which has to be influenced by the infrastructure by some means as it's pretty much a layer on top of the template but doesn't really add any caching.



来源:https://stackoverflow.com/questions/10600162/what-the-overhead-of-java-orm-for-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!