prometheus/tsdb
Ganesh Vernekar d4b9fe801f
M-map full chunks of Head from disk (#6679)
When appending to the head and a chunk is full it is flushed to the disk and m-mapped (memory mapped) to free up memory

Prom startup now happens in these stages
 - Iterate the m-maped chunks from disk and keep a map of series reference to its slice of mmapped chunks.
- Iterate the WAL as usual. Whenever we create a new series, look for it's mmapped chunks in the map created before and add it to that series.

If a head chunk is corrupted the currpted one and all chunks after that are deleted and the data after the corruption is recovered from the existing WAL which means that a corruption in m-mapped files results in NO data loss.

[Mmaped chunks format](https://github.com/prometheus/prometheus/blob/master/tsdb/docs/format/head_chunks.md)  - main difference is that the chunk for mmaping now also includes series reference because there is no index for mapping series to chunks.
[The block chunks](https://github.com/prometheus/prometheus/blob/master/tsdb/docs/format/chunks.md) are accessed from the index which includes the offsets for the chunks in the chunks file - example - chunks of series ID have offsets 200, 500 etc in the chunk files.
In case of mmaped chunks, the offsets are stored in memory and accessed from that. During WAL replay, these offsets are restored by iterating all m-mapped chunks as stated above by matching the series id present in the chunk header and offset of that chunk in that file.

**Prombench results**

_WAL Replay_

1h Wal reply time
30% less wal reply time - 4m31 vs 3m36
2h Wal reply time
20% less wal reply time - 8m16 vs 7m

_Memory During WAL Replay_

High Churn:
10-15% less RAM -  32gb vs 28gb
20% less RAM after compaction 34gb vs 27gb
No Churn:
20-30% less RAM -  23gb vs 18gb
40% less RAM after compaction 32.5gb vs 20gb

Screenshots are in [this comment](https://github.com/prometheus/prometheus/pull/6679#issuecomment-621678932)


Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
2020-05-06 21:00:00 +05:30
..
chunkenc storage: Added Chunks{Queryable/Querier/SeriesSet/Series/Iteratable. Added generic Merge{SeriesSet/Querier} implementation. (#7005) 2020-03-24 20:15:47 +00:00
chunks M-map full chunks of Head from disk (#6679) 2020-05-06 21:00:00 +05:30
cmd/tsdb Use .UTC everywhere we use time.Unix (#7066) 2020-03-29 17:35:39 +01:00
docs/format M-map full chunks of Head from disk (#6679) 2020-05-06 21:00:00 +05:30
encoding Avoid WriteAt for Postings. 2019-12-16 15:30:49 +00:00
errors Moving tsdb into its own subdirectory 2019-08-13 13:58:49 +05:30
fileutil Replace fileutil.ReadDir with ioutil.ReadDir (#7029) (#7033) 2020-04-06 19:04:20 +05:30
goversion Fix some typo in comments (#6730) 2020-01-31 12:11:52 +05:30
index Goroutine: Fix ambiguous variable (#7175) 2020-04-28 11:02:26 +01:00
record Spelling (#6517) 2020-01-02 15:54:09 +01:00
test Port tsdb to use pkg/labels. (#6326) 2019-11-18 11:53:33 -08:00
testdata Handle V1 indexes, some of which have unsorted posting offset tables. (#6564) 2020-01-06 14:06:11 +00:00
tombstones tsdb: add tombstonesHeaderSize constant (#7028) 2020-03-22 12:59:35 +05:30
tsdbutil storage: Added Chunks{Queryable/Querier/SeriesSet/Series/Iteratable. Added generic Merge{SeriesSet/Querier} implementation. (#7005) 2020-03-24 20:15:47 +00:00
wal Capitalizing first letter of all log lines (#7043) 2020-04-11 09:22:18 +01:00
.gitignore Moving tsdb into its own subdirectory 2019-08-13 13:58:49 +05:30
CHANGELOG.md Spelling (#6517) 2020-01-02 15:54:09 +01:00
README.md Edit TSDB README badges 2019-10-24 15:35:47 +05:30
block.go Revert head posting optimization 2020-03-25 20:19:33 +01:00
block_test.go M-map full chunks of Head from disk (#6679) 2020-05-06 21:00:00 +05:30
compact.go Capitalizing first letter of all log lines (#7043) 2020-04-11 09:22:18 +01:00
compact_test.go M-map full chunks of Head from disk (#6679) 2020-05-06 21:00:00 +05:30
db.go M-map full chunks of Head from disk (#6679) 2020-05-06 21:00:00 +05:30
db_test.go M-map full chunks of Head from disk (#6679) 2020-05-06 21:00:00 +05:30
head.go M-map full chunks of Head from disk (#6679) 2020-05-06 21:00:00 +05:30
head_bench_test.go M-map full chunks of Head from disk (#6679) 2020-05-06 21:00:00 +05:30
head_test.go M-map full chunks of Head from disk (#6679) 2020-05-06 21:00:00 +05:30
isolation.go Do not attempt isolation for appendID == 0 2020-03-01 02:48:35 +01:00
mocks_test.go Revert head posting optimization 2020-03-25 20:19:33 +01:00
querier.go Make sure deleted intervals are excluded from Seek (#6980) 2020-04-23 10:00:30 +01:00
querier_bench_test.go M-map full chunks of Head from disk (#6679) 2020-05-06 21:00:00 +05:30
querier_test.go M-map full chunks of Head from disk (#6679) 2020-05-06 21:00:00 +05:30
repair.go Capitalizing first letter of all log lines (#7043) 2020-04-11 09:22:18 +01:00
repair_test.go Port tsdb to use pkg/labels. (#6326) 2019-11-18 11:53:33 -08:00
tsdbblockutil.go M-map full chunks of Head from disk (#6679) 2020-05-06 21:00:00 +05:30
wal.go Capitalizing first letter of all log lines (#7043) 2020-04-11 09:22:18 +01:00
wal_test.go Replace fileutil.ReadDir with ioutil.ReadDir (#7029) (#7033) 2020-04-06 19:04:20 +05:30

README.md

TSDB

GoDoc

This repository contains the Prometheus storage layer that is used in its 2.x releases.

A writeup of its design can be found here.

Based on the Gorilla TSDB white papers.

Video: Storing 16 Bytes at Scale from PromCon 2017.

See also the format documentation.