|
12 | 12 | - [By/Without and Ignoring/On](#bywithout-and-ignoringon) |
13 | 13 | - [Authentication and encryption for Prometheus and its exporters](#authentication-and-encryption-for-prometheus-and-its-exporters) |
14 | 14 | - [Prometheus and fsync](#prometheus-and-fsync) |
| 15 | + - [`min-block-duration` and `max-block-duration`](#min-block-duration-and-max-block-duration) |
15 | 16 |
|
16 | 17 | ## `avg_over_time` |
17 | 18 |
|
@@ -173,6 +174,21 @@ What fsync means in Prometheus: |
173 | 174 |
|
174 | 175 | I found a link: <https://groups.google.com/g/prometheus-users/c/Oy1qI3Og9ww> but the logic seems to be changed in the current source code (v3.8.0). |
175 | 176 |
|
| 177 | +I use [deepwiki](https://deepwiki.com/search/when-fsync-is-performed_cbf97034-616c-403a-8ff3-de92da849479) to check how fsync is performed in Prometheus. |
| 178 | +- The WAL implementation performs fsync in several scenarios: |
| 179 | + - During segment rotation: When creating a new segment, the previous segment is fsynced asynchronously via `w.fsync(prev)`. |
| 180 | + - During close operation: The active segment is fsynced before closing. |
| 181 | + - Manual sync: Available via `Sync()` method for testing. |
| 182 | +- During compaction, temporary block directories are fsynced before being made visible. |
| 183 | +- Both the chunk writer and head chunk disk mapper perform fsync when finalizing files: |
| 184 | + - Chunk writer calls `tf.Sync()` during `finalizeTail()`. |
| 185 | + - Head chunk mapper calls `cdm.curFile.Sync()` during `finalizeCurFile()`. |
| 186 | + |
| 187 | +According to the documentation, WAL syncs typically happen every two hours during normal operation, though the actual fsync frequency is higher during active writes due to the WAL's design. |
| 188 | + |
| 189 | +> [!note] |
| 190 | +> The WAL implementation uses asynchronous fsync for segment rotation to avoid blocking writes, while compaction and chunk operations use synchronous fsync to ensure data integrity before making files visible. The WAL also tracks fsync duration as a metric for monitoring performance impact. |
| 191 | +
|
176 | 192 | ## `min-block-duration` and `max-block-duration` |
177 | 193 |
|
178 | 194 | In Prometheus, the `--storage.tsdb.min-block-duration` and `--storage.tsdb.max-block-duration` flags control the time range of data stored in individual, on-disk data blocks |
|
0 commit comments