Announcement Announcement Module
No announcement yet.
MongoDB Spring Data - Is Fire & Forget Used??? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • MongoDB Spring Data - Is Fire & Forget Used???

    So MongoDB has a "fire & forget" setting for its Java driver.

    That setting dictates if, after typically an insert is done, the client bothers to check if the insert went correctly.

    So, what's the default for Spring Data's MongoDB? Wait for the acknowledgement, or not? And how do I change this setting?

  • #2
    I think it's detailed in here.

    Example usage from my mongoTemplate definition :

    HTML Code:
    <property name="WriteResultChecking">
                   static-field="" />


    • #3
      Hey thanks albert...but...

      I'm not sure if this setting effects if I use mongo:repositories interface scanner? In other words my interface w/o an implementation looks like:

      public interface PatientRepository extends MongoRepository<Patient, String> {
      	List<Patient> findByLastName(String lastname);
      I say I'm not sure if the MongoTemplate impacts interfaces ^ like that, because I ran a load test of 5000 insert requests with the WriteResultChecking set to EXCEPTION, then 5000 insert requests with it set to NONE, and I see no difference in times.

      I would of expected there be some difference in performance???


      • #4
        Hi again !

        I think that's good news, meaning the spring and mongodb rocks and lightning fast, haha.

        Perhaps the issue is related with this :

        I assume WriteConcern defaults to normal, and :
        NORMAL == Exceptions are raised for network issues, but not server errors

        And also, it's so fast, perhaps for this reason (quoted from here):
        To be fair, the default setup with MongoDB is to flush to disk every 60 seconds. So you still have a 60 second window of data loss.

        You can use journaling and drop that window to 100ms, but that will tax the IO more heavily.
        You can also configure your writers to wait on that journal to flush (WriteConcern: fsync), but that's going to slow down writes significantly.
        To set the writeconcern to fsync, one can try this :
        HTML Code:
        <property name="WriteConcern">
        	<util:constant static-field="com.mongodb.WriteConcern.FSYNC_SAFE" />


        • #5
          The information above (as well as in the linked StackOverflow post) is kind of out of date... here are the docs for the latest java driver:

          Also see here:

          If you are running the server in --journal mode, then FSYNC_SAFE and JOURNAL_SAFE should do the same thing, which is to ensure the journal group commit is done before returning. See here:

          You can set the interval for journal group commits by using the --journalCommitInterval parameter to as low as 2ms, and if a getLastError command is waiting, MongoDB will potentially execute the journal group commit up to as small as 1/3 of the time before the next interval.

          Ideally, Spring Data would support setting the WriteConcern on a per-operation basis, so that you could do things like insert, insert, insert, insert-with-JOURNAL-SAFE, but I don't think you can do that yet.