What is MongoDB fsync?

I have been using MongoDB for some time and have seen fsync expect data to be flushed to disk. Ok, so I thought this was a data security solution.

It worked well, takes much longer than the SQL alternative. Then I saw that I could set syncdelay to 0 , then the speed returned, but I wondered how it would be in the future with many parallel queries. So I removed the fsync parameter from the updates and inserted and removed the syncdelay configuration syncdelay .

To check if the data was being recorded, I quickly checked Rockmongo after I did the update, and the data was actually there, really fast!

So what is fsync if it makes recordings slow, and without them recordings happen, and in any case fast?

+6
source share
3 answers

Per Mongo Documentation:

The main use of fsync is to clean and lock the database for backup.

and

The fsync operation blocks all other write operations while it is running.

Apparently, the reason is blocking.

+5
source

fsync is technically an admin command that forces a stream of all data to disk. You should not use it in your code, as a rule, at least. It was used to lock the database for backup, etc.

Data security in MongoDB comes from replication / scalding / logging, rather than forced write. This kind of thing wins.

The Java driver wraps this write-and-sync concept in the WriteConcern class, which I never liked. You will not need to decide which part of your data is more or less important, but simply trusts the tool to do its job.

Also, if you set syncdelay to zero, make sure you turn off logging. See this .

+4
source

As other answers said, the fsync command forces a flash and is usually used right before locking data files for an instant.

The getLastError section has the "fsync" option for worrying about a record that will wait to return to all pending data that has been flushed to disk. Usually you do not use this, but the "j" option (which returns as soon as logging occurs) returns much faster and still provides long-term recording. You can go through the update / insert command as a safe option in the driver of your choice to let it automatically run the getLastError command for you.

0
source

Source: https://habr.com/ru/post/920751/


All Articles