LSM-tree. In this work, we have identified that this problem
often causes latency spikes due to the decreased cache hit
rates. We refer to it as the cache invalidation problem.
Such cache invalidations happen frequently in workloads
with intensive writes and updates, such as order-placement
on hot merchandises in e-commerce workloads. Figure 1
shows an example where the cache misses caused by such
invalidations leads up to 10× latency spikes and 90% queries
per second (QPS) drops in X-Engine [14], a high-performance
LSM-tree based storage engine at Alibaba and Alibaba Cloud.
This level of performance instability introduces potential
risks for mission-critical applications. Meanwhile, off-peak
scheduling of compactions cannot maintain high performance
under high stress, because it accumulates a large number of
levels which lead to severe performance degradation in LSM-
tree (e.g., the accrued range deletion operations have fatal
performance reduction to range selection queries [35]). Be-
yond this, we aim to provide a general database service on
the cloud, so that we cannot ignore the cache invalidation
problem when users need high performance (i.e., under high
stress).
The cache invalidation problem has attracted some re-
search attention in the past [11, 1, 37]. They try to decrease
the frequency of compactions by relaxing the sorted data
layout of the LSM-tree [15], or maintain a mapping between
records before and after compactions [1, 40]. Furthermore,
they often require significant changes to the LSM-tree im-
plementation. Hence, they either sacrifice the range query
performance, or the space efficiency, or introduce signifi-
cant extra overhead. These are often unacceptable because
many industrial applications prefer general-purpose storage
engines offering competitive performance for both point and
range queries with high memory and space efficiencies.
In this paper, we introduce machine learning techniques to
capture the data access trends during and after compactions
that cannot be captured by existing methods. Our proposal
introduces a small overhead without adding or altering any
data structures in the LSM-tree. More specifically, we pro-
pose a learned prefetcher, Leaper, to predict which records
would be accessed during and after compactions using ma-
chine learning models, and prefetch them into the cache ac-
cordingly. Our key insight is to capture data access trends
at the range level, and intersects hot ranges with record
block boundaries to identify record blocks for prefetching
into the cache. We are enabled by machine learning models
to find such hot ranges from the workload, which cannot be
identified by conventional cache replacement policies. The
identified ranges are independent of background operations,
allowing Leaper to perform across multiple compactions or
flushes continuously. And, our method naturally supports
both point and range queries.
We design and implement Leaper to minimize both of-
fline training overhead and online inference overhead. To
this end, we have applied several optimizations in the imple-
mentation such as the locking mechanism and the two-phase
prefetcher. We have evaluated Leaper using both synthetic
and real-world workloads. Results show that Leaper is able
to reduce cache invalidations and latency spikes by 70% and
99%, respectively. The training and inference overheads of
Leaper are constrained to 6 seconds and 5 milliseconds, re-
spectively. Our main contributions are as follows:
• We formulate the cache invalidation problem, and iden-
tify its root causes in the modern LSM-tree storage
engines, which existing methods cannot address. We
have proposed a machine learning-based approach, Le-
aper, to predict future hot records and prefetch them
into the cache, without being disturbed by background
LSM-tree operations that cause the cache invalidation
problem.
• We have achieved a low training and inference over-
head in our machine learning-based proposal by care-
fully formulating the solution, selecting light-weight
models for predictions and optimizing the implemen-
tation. The overall overhead is often as small as 0.95%
(compared to the cost of other normal execution op-
erations excluding Leaper) as observed in real-world
workloads. We have extracted effective features, achie-
ving a high level of accuracy: 0.99 and 0.95 recall
scores for synthetic and real-world workloads, respec-
tively.
• We have evaluated our proposal by comparing it with
the state-of-the-art baselines using both synthetic and
real-world workloads. Experimental results show that
Leaper improves the QPS by more than 50% in average
and eliminates about 70% cache invalidations and 99%
of latency spikes, significantly outperforming others.
The remainder of this paper is organized as follows. Sec-
tion 2 introduces the background and formulates the cache
invalidation problem. Section 3 presents our design overview
of Leaper. We introduce details of Leaper’s components in
Sections 4, 5 and 6. We evaluate our proposal in Section 7
and discuss related works in Section 8. At last, we conclude
in Section 9.
2. BACKGROUND AND PRELIMINARY
2.1 LSM-tree based Storage Engines
LSM-tree based storage engines have acquired significant
popularity in recent years. Notable examples include Lev-
elDB [10] from Google, RocksDB [7] from Facebook and X-
Engine [14] from Alibaba, supporting applications such as
Chrome [17], LinkedIn [8], and DingTalk [14]. This popu-
larity is driven by the trend that there are increasingly more
writes (e.g., inserts, updates) in database workloads, where
the traditional B-tree based storages struggle to offer the
expected performance at a reasonable space cost.
LSM-tree is designed to achieve a high write through-
put. Figure 2 illustrates the generic architecture of a LSM-
tree, consisting of a memory-resident component and a disk-
resident component. Incoming records are inserted into ac-
tive memtables in the main memory, which are implemented
as skiplists in many systems [31, 14]. To update an existing
record, the corresponding delta is inserted into this active
memtable in the same way. This append-only design ensures
that all writes other than logging are completed in the main
memory without going into the durable storage where the
access latency is much higher. When an active memtable
is filled, it is switched to be an immutable memtable. As
memtables accumulate in the main memory, approaching
the main memory capacity, flush operations are triggered
to flush some immutable memtables into the durable storage
where incoming records are merged with existing ones. Such
a merge may incur a lot of disk I/Os. And, the same record
may be merged multiple times, causing write amplifications.
To bound such write amplifications and to facilitate fast
lookups over recently flushed records which are still very
1977
评论