What the overhead of Java ORM for MongoDB

2019-03-13 17:26发布

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,

3条回答
Lonely孤独者°
2楼-- · 2019-03-13 18:06

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.

查看更多
走好不送
3楼-- · 2019-03-13 18:10

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.

查看更多
何必那么认真
4楼-- · 2019-03-13 18:27

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?

查看更多
登录 后发表回答