Skip to content
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

Improve performance of saving entities by using insert(…) if possible [DATAMONGO-1054] #1975

Closed
spring-projects-issues opened this issue Sep 12, 2014 · 4 comments

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Sep 12, 2014

Titi Wangsa opened DATAMONGO-1054 and commented

Mongo Template has this method:

void insert(Collection<? extends Object> batchToSave, Class<?> entityClass);

that does a bulk insert

Basic repository interfaces that extend from MongoRepository does not have it. They have:

<S extends T> List<S> save(Iterable<S> entites);

this is considerably much slower.

actual:
saving using
MongoRepository.save(Iterable<S> entites)
for 6,000+ items took a few minutes when write concern is set to journaled

expected
ability to save it in matter of milliseconds
by using
MongoOperation.insert(Collection<? extends Object> batchToSave, Class<?> entityClass);

workaround:
I created a CustomImpl that for my repository class that calls mongoOperation. this is much faster. I am hoping that it .insert would be a built-in feature on the next release


Attachments:

Issue Links:

  • DATAMONGO-903 Add insert method to MongoRepository interface
    ("supersedes")

Referenced from: pull request #253, and commits 2e74c19, 1b7e077, e58fa28, 7ebaf93, 714446b, a212b75, fa2c609

Backported to: 1.6.2 (Evans SR2)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 12, 2014

Oliver Drotbohm commented

Sounds like a legit request. Any chance you provide a tiny test case that shows the performance improvement?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 13, 2014

Titi Wangsa commented

sample project to show the perfomance impact of MongoRepository.save vs MongoTemplate.insert.

here is the output of: mvn clean test
Sep 13, 2014 10:06:44 PM test.test.ShorelineRepositoryTest testSave
INFO: shorelineRepository.save took 17492ms
Sep 13, 2014 10:06:44 PM test.test.ShorelineRepositoryTest testInsert
INFO: mongoTemplate.insert took 40ms

mongo --version
MongoDB shell version: 2.6.4

java -version
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

uname -a
Darwin titis-mbp 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 28, 2014

Thomas Darimont commented

Please revise

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Nov 28, 2014

Oliver Drotbohm commented

We're now optimizing calls to the save(…) by checking whether the given entities are considered new (determined by inspecting the identifier). In case they're all new we trigger the insert(…) method instead of save(…). For modeling scenarios with manually assigned identifiers Thomas introduced dedicated insert(…) methods on MongoRepository so that you can force inserts to be used. We generally recommend sticking to save(…) or explicitly declaring the insert(…) methods on your repository to avoid exposing a store specific repository to clients

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants