gerrit/lib
Hugo Arès 00fc15ac00 Reduce chance of deadlock in account cache
This deadlock is not the typical deadlock where 2 threads locked a
resource and each one is waiting to lock a second resource already
locked by the other thread. The thread owning the account cache lock is
parked, which tell us that the locked was not released. I could not
determine the exact sequence of events leading to this deadlock making
it really hard to report/fix the problem.

While investigating, I realized that there quite a few reported issues
in Guava that could be major for Gerrit:

  Our deadlock happening in account cache
  https://bugs.chromium.org/p/gerrit/issues/detail?id=7645

  Other deadlock
  https://github.com/google/guava/issues/2976
  https://github.com/google/guava/issues/2863

  Performance
  https://github.com/google/guava/issues/2063

  Race condition
  https://github.com/google/guava/issues/2971

Because I could not reproduce the deadlock in a dev environment or in
a unit test making it almost impossible to fix, I considered other
options such as replacing Guava by something else.

The maintainer of Caffeine[1] cache claims that Caffeine is a high
performance[2], near optimal caching library designed/implemented base
on the experience of designing Guava's cache and ConcurrentLinkedHashMap.
I also did some benchmarks about spawning a lot of threads reading/writing
values from the caches. I ran those benchmarks on both Guava and Caffeine
and Guava was always taking at least double the time than Caffeine to
complete all operations.

Migrating to Caffeine is almost a drop-in replacement. Caffeine
interface are very similar to Guava cache and there is an adapter to
migrate to Caffeine and keep using Guava's interfaces. After migrating
to Caffeine, we saw that deadlock occurrence was reduced from once a day
to once every 2 weeks in our production server.

The maintainer of Caffeine, Ben Manes pointed us to the possible
cause[3] of this issue, a bug[4] in the kernel and its fix[5]. Our
kernel version is supposed to have the fix but we will try another OS
and kernel version.

Replacing Guava caches by Caffeine brings 2 things, it reduces the
chances of having the deadlock most likely caused by a kernel bug and
improve the cache performance.

[1]https://github.com/ben-manes/caffeine
[2]https://github.com/ben-manes/caffeine/wiki/Benchmarks
[3]https://groups.google.com/forum/#!topic/mechanical-sympathy/QbmpZxp6C64
[4]b0c29f79ec
[5]76835b0ebf

Bug: Issue 7645
Change-Id: I8d2b17a94d0e9daf9fa9cdda563316c5768b29ae
2018-02-22 18:53:47 +00:00
..
antlr Remove Buck based build 2017-01-23 12:44:58 +00:00
asciidoctor Replace FileInputStream and FileOutputStream with static Files methods 2017-05-10 00:10:52 +00:00
auto Remove Buck based build 2017-01-23 12:44:58 +00:00
bouncycastle Don't ship bouncycastle libraries in plugin API 2017-04-07 07:38:04 +02:00
codemirror Update codemirror to 5.25.0 2017-03-22 21:44:40 +00:00
commons Remove Buck based build 2017-01-23 12:44:58 +00:00
dropwizard Remove Buck based build 2017-01-23 12:44:58 +00:00
easymock Remove Buck based build 2017-01-23 12:44:58 +00:00
elasticsearch Remove Buck based build 2017-01-23 12:44:58 +00:00
fonts Remove Buck based build 2017-01-23 12:44:58 +00:00
greenmail Remove Buck based build 2017-01-23 12:44:58 +00:00
guice Remove Buck based build 2017-01-23 12:44:58 +00:00
gwt Remove Buck based build 2017-01-23 12:44:58 +00:00
highlightjs PolyGerrit: Add support for erlang and puppet in highlight 2017-07-14 02:55:21 +01:00
httpcomponents Remove Buck based build 2017-01-23 12:44:58 +00:00
jackson Remove Buck based build 2017-01-23 12:44:58 +00:00
jetty Remove Buck based build 2017-01-23 12:44:58 +00:00
jgit Update JGit to 4.7.1.201706071930-r 2017-06-08 20:58:02 +09:00
joda Remove Buck based build 2017-01-23 12:44:58 +00:00
js update web-component-tester to 5.0.0. 2017-02-01 13:33:56 +01:00
jsoup Remove one last buck file from gerrit's core 2017-01-27 19:41:56 +00:00
log Remove Buck based build 2017-01-23 12:44:58 +00:00
lucene Remove Buck based build 2017-01-23 12:44:58 +00:00
mail Remove Buck based build 2017-01-23 12:44:58 +00:00
mime4j Remove Buck based build 2017-01-23 12:44:58 +00:00
mina Format lib/mina/BUILD with buildifier 2017-03-30 17:31:27 +09:00
openid Remove Buck based build 2017-01-23 12:44:58 +00:00
ow2 Remove Buck based build 2017-01-23 12:44:58 +00:00
polymer_externs Add transpilation to PolyGerrit 2017-05-15 17:00:01 +09:00
powermock Bazel: Fix powermock-core declaration 2017-01-24 23:31:15 +01:00
prolog Bazel: Allow plugins to non-transitively depend on prolog rules 2017-05-17 08:51:13 +02:00
BUILD Reduce chance of deadlock in account cache 2018-02-22 18:53:47 +00:00
guava.bzl Upgrade Guava to 22.0 2017-11-02 19:10:14 +00:00
LICENSE-antlr Build with Buck 2013-05-09 13:40:36 +00:00
LICENSE-Apache1.1 Build with Buck 2013-05-09 13:40:36 +00:00
LICENSE-Apache2.0 Build with Buck 2013-05-09 13:40:36 +00:00
LICENSE-args4j Synchronize args4j license with upstream 2016-06-07 18:59:40 +00:00
LICENSE-asciidoctor Add correct license for asciidoctor 2016-08-19 04:05:06 +00:00
LICENSE-automaton Synchronize automaton license with upstream 2016-06-09 09:31:58 +00:00
LICENSE-bouncycastle Synchronize bouncy castle license with upstream 2016-06-10 06:31:21 +02:00
LICENSE-CC0-1.0 Add support for elliptic curve/ed25519 SSH keys 2017-03-28 15:26:29 +00:00
LICENSE-CC-BY3.0-unported Clarify that the CC-BY 3.0 license is the unported version 2016-09-21 11:19:22 +02:00
LICENSE-clippy Build with Buck 2013-05-09 13:40:36 +00:00
LICENSE-codemirror-minified Use a pre-built minified CodeMirror in the release build 2016-04-04 20:33:27 -04:00
LICENSE-codemirror-original Use a pre-built minified CodeMirror in the release build 2016-04-04 20:33:27 -04:00
LICENSE-diffy Diffy should use the unported CC-BY 3.0 license 2016-09-21 11:26:15 +02:00
LICENSE-DO_NOT_DISTRIBUTE Build with Buck 2013-05-09 13:40:36 +00:00
LICENSE-es6-promise Add es6-promise for Internet Explorer 2016-09-13 15:14:32 +00:00
LICENSE-fetch Add fetch polyfill for use in all supported browsers 2016-03-03 23:49:18 -05:00
LICENSE-h2 Build with Buck 2013-05-09 13:40:36 +00:00
LICENSE-highlightjs Syntax highlighting 2016-07-25 13:47:30 -07:00
LICENSE-icu4j Adds the Soy library and injects it via EmailArguments 2016-08-22 09:45:33 -07:00
LICENSE-jgit Build with Buck 2013-05-09 13:40:36 +00:00
LICENSE-jsch Build with Buck 2013-05-09 13:40:36 +00:00
LICENSE-jsoup Add jsoup to Buck and Bazel 2016-11-16 01:24:59 +00:00
LICENSE-moment Recognize time format preferences. 2016-03-15 15:22:39 -07:00
LICENSE-MPL1.1 Build with Buck 2013-05-09 13:40:36 +00:00
LICENSE-OFL1.1 Serve fonts from Gerrit instead of Google Fonts. 2016-04-01 13:11:02 -04:00
LICENSE-ow2 Build with Buck 2013-05-09 13:40:36 +00:00
LICENSE-page.js Build bower_components with buck 2015-11-12 19:01:53 -05:00
LICENSE-polymer Build bower_components with buck 2015-11-12 19:01:53 -05:00
LICENSE-postgresql Build with Buck 2013-05-09 13:40:36 +00:00
LICENSE-prologcafe Update license text for PrologCafe 2013-05-13 09:44:25 -07:00
LICENSE-promise-polyfill Build bower_components with buck 2015-11-12 19:01:53 -05:00
LICENSE-protobuf Add dependency on the Google protocol buffer library 2013-09-10 15:59:25 -07:00
LICENSE-PublicDomain Build with Buck 2013-05-09 13:40:36 +00:00
LICENSE-silk_icons Synchronize license for silk icons 2016-09-21 11:04:46 +02:00
LICENSE-slf4j Build with Buck 2013-05-09 13:40:36 +00:00
LICENSE-xz Download commands: Add JGit archive 2014-03-03 23:34:46 +00:00