Commit 68fbff8
committed
Reduce the lock hold time during Map.clear (fixes #835)
When invalidating the cache, it is faster and simpler to discard under
the eviction lock. This avoids thrashing on the write buffer and causing
excessive maintenence runs, which are triggered per write. However, for
a large cache this hold time may be excessive by causing other writes to
pile up so that the write buffer is full and backpressure causes delays.
In that case removing through the write buffer allows fairer throughput
as all writes compete to append into the buffer and async draining will
captures a batch of work. This avoids delaying any other write, or at
least makes the backpressure times short, so that writes have better
latencies by disfavoring the clear throughput.
The cache adapts strategies by monitoring the size of the write buffer.
If it grows over a threshold then the clear operation backs off by
releasing the eviction lock and performing a one-by-one removal instead.1 parent 2fbc869 commit 68fbff8
File tree
4 files changed
+48
-20
lines changed- caffeine/src
- main/java/com/github/benmanes/caffeine/cache
- test/java/com/github/benmanes/caffeine/cache
- gradle
4 files changed
+48
-20
lines changedLines changed: 17 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1989 | 1989 | | |
1990 | 1990 | | |
1991 | 1991 | | |
1992 | | - | |
1993 | 1992 | | |
1994 | 1993 | | |
1995 | 1994 | | |
1996 | | - | |
| 1995 | + | |
| 1996 | + | |
1997 | 1997 | | |
1998 | 1998 | | |
1999 | 1999 | | |
2000 | 2000 | | |
2001 | 2001 | | |
2002 | 2002 | | |
2003 | 2003 | | |
2004 | | - | |
2005 | | - | |
2006 | | - | |
2007 | | - | |
2008 | | - | |
2009 | 2004 | | |
2010 | 2005 | | |
2011 | 2006 | | |
2012 | 2007 | | |
2013 | 2008 | | |
2014 | 2009 | | |
2015 | | - | |
2016 | | - | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
2017 | 2020 | | |
2018 | 2021 | | |
2019 | 2022 | | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
2020 | 2028 | | |
2021 | 2029 | | |
2022 | 2030 | | |
| |||
Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
142 | 161 | | |
143 | 162 | | |
144 | 163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | | - | |
| 168 | + | |
| 169 | + | |
169 | 170 | | |
170 | 171 | | |
171 | 172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
| |||
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | 84 | | |
89 | 85 | | |
90 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| |||
0 commit comments