Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Guava cache with Caffeine cache for vertex cache #3188

Merged
merged 1 commit into from
Aug 31, 2022

Conversation

ministat
Copy link
Contributor

@ministat ministat commented Aug 28, 2022

Fix the issue #3185

Guava cache has performance bug in 100% read scenario. The solution is to use Caffeine cache which is also suggested by Guava community. See google/guava#2408 for more details. Meanwhile, Caffeine cache beats Guava cache in all scenarios.

The following result is for read scenario.

Benchmark (cacheType) Mode Cnt Score Error Units
VertexCacheBenchmark.run guava avgt 5 0.001 ± 0.001 ms/op
VertexCacheBenchmark.run caffeine avgt 5 ≈ 10⁻⁴ ms/op


Thank you for contributing to JanusGraph!

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

For all changes:

  • Is there an issue associated with this PR? Is it referenced in the commit message?
  • Does your PR body contain #xyz where xyz is the issue number you are trying to resolve?
  • Has your PR been rebased against the latest commit within the target branch (typically master)?
  • Is your initial contribution a single, squashed commit?

For code changes:

  • Have you written and/or updated unit tests to verify your changes?
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE.txt file, including the main LICENSE.txt file in the root of this repository?
  • If applicable, have you updated the NOTICE.txt file, including the main NOTICE.txt file found in the root of this repository?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 28, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: ministat / name: Hongjiang Zhang (e479200)

@janusgraph-bot janusgraph-bot added the cla: external Externally-managed CLA label Aug 28, 2022
@porunov
Copy link
Member

porunov commented Aug 29, 2022

Thank you for the contribution @ministat , @clovertrail !
Replacing Guava cache with Caffeine cache definitely makes sense to me.
That said, to accept your contribution you need to sign CLA to give JanusGraph permission to use the contribution you created.
Would you be able to sign EasyCLA?
Signing a CLA might be a problem if you signed CLA for one GitHub account but made a commit using information from another GitHub account.
In your case I see that the commit is made by @clovertrail but the PR is opened by @ministat .
In this case you need to use clovertrail as a GitHub account when signing EasyCLA.
If you intended to use ministat account then you will need to change the author of the commit to use name and email of ministat GitHub account.
Below I will show possible solutions on how to correctly sign the commit in your case.

  1. Solution 1 - the case when you want to use ministat account only. In this case we need to update commit with the correct author information and sign the commit (by using -s parameter).
git config user.name "Hongjiang Zhang"
git config user.email "[email protected]"
git commit --amend -s --author="Hongjiang Zhang <[email protected]>"
git push -f

After that login into GitHub with ministat username. And click the next link to sign CLA:
https://api.easycla.lfx.linuxfoundation.org/v2/repository-provider/github/sign/1543822/77385607/3188/#/?version=2

  1. Solution 2 - the case when you want to use clovertrail account only.
git config user.name "Your Full Name"
git config user.email "[email protected]"
git commit --amend -s
git push -f

After that login into GitHub with clovertrail username. And click the next link to sign CLA:
https://api.easycla.lfx.linuxfoundation.org/v2/repository-provider/github/sign/1543822/77385607/3188/#/?version=2

Please, let me know if you have any problems with signing EasyCLA, and I will help you with signing it.

@ministat ministat force-pushed the vertex_cache_by_caffeine_cache branch 2 times, most recently from 7ffd610 to e479200 Compare August 29, 2022 14:51
@ministat
Copy link
Contributor Author

@porunov Thanks for your suggestion. I have passed the CLA checked. Appreciated!

Copy link
Member

@porunov porunov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking the dependency tree I see that we get Caffeine 2.3.1 from TinkerPop dependency (org.apache.tinkerpop:gremlin-groovy:3.5.4).
I'm just thinking if we should use the latest Caffeine 3.1.1 or should we stick to the one provided by TinkerPop. Do you know if there were any breaking changes? If no, then I would prefer trying out the latest Caffeine dependency 3.1.1.

UPDATE: I see in the documentation (https://github.com/ben-manes/caffeine#download) that for Java 11 we should use 3.x Caffeine but for anything else we should use 2.x Caffeine, so, I think using Caffeine 2.9.3 should be safe.

@ben-manes
Copy link

@porunov The main reason for the major version bump was that v3.x requires Java 11 or higher, whereas previously it was Java 8. This allowed the implementation code to switch from sun.misc.Unsafe to VarHandles (fully removed in 3.0.2). Otherwise the changes were minor clean ups that had little impact on users (see release notes).

@porunov
Copy link
Member

porunov commented Aug 29, 2022

@porunov The main reason for the major version bump was that v3.x requires Java 11 or higher, whereas previously it was Java 8. This allowed the implementation code to switch from sun.misc.Unsafe to VarHandles (fully removed in 3.0.2). Otherwise the changes were minor clean ups that had little impact on users (see release notes).

Thank you for the clarification! JanusGraph supports Java 11 but we still write everything in Java 8 to support clients on Java 8, so I think in this case it should be safe to use Caffeine 2.9.3.

Copy link
Member

@porunov porunov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks good but I have small nitpicks below.

Could you please add explicit Caffeine dependency to root pom.xml like the next:

<dependency>
    <groupId>com.github.ben-manes.caffeine</groupId>
    <artifactId>caffeine</artifactId>
    <version>${caffeine.version}</version>
</dependency>

Also, specify <caffeine.version>2.9.3</caffeine.version>.

volatileVertices = new NonBlockingHashMapLong<>(initialDirtySize);
log.debug("Created dirty vertex map with initial size {}", initialDirtySize);

cache = Caffeine.newBuilder().maximumSize(maxCacheSize)
Copy link
Member

@porunov porunov Aug 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not an issue, just leaving the information below)
For other reviewers who are interested why there is no concurrencyLevel option in Caffeine, I found this great explanation by @ben-manes https://groups.google.com/g/guava-discuss/c/BnoN9q9fDgw/m/6kF6H2aLAgAJ

Moreover, notice that the concurencyLevel here was always 1.

@porunov
Copy link
Member

porunov commented Aug 29, 2022

@ministat ignore failed Hbase and dist tests. Looks like there is a problem with getting docker image for some reason but it's unrelated to your changes. (more details are here #3190)

@ministat ministat force-pushed the vertex_cache_by_caffeine_cache branch from e479200 to 11f130f Compare August 30, 2022 07:31
@ministat
Copy link
Contributor Author

Add explicit Caffeine dependency, and excludes the lower version of org.checkerframework:checker-qual from guava, otherwise, there are many dependency convergence errors like the following:

Dependency convergence error for org.checkerframework:checker-qual:jar:3.12.0:compile paths to dependency are:
+-org.janusgraph:janusgraph-dist:pom:1.0.0-SNAPSHOT
  +-org.apache.tinkerpop:hadoop-gremlin:jar:3.5.4:compile
    +-com.google.guava:guava:jar:31.1-jre:compile
      +-org.checkerframework:checker-qual:jar:3.12.0:compile
and
+-org.janusgraph:janusgraph-dist:pom:1.0.0-SNAPSHOT
  +-org.apache.tinkerpop:gremlin-groovy:jar:3.5.4:compile
    +-com.github.ben-manes.caffeine:caffeine:jar:2.9.3:compile
      +-org.checkerframework:checker-qual:jar:3.19.0:compile

[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:
Failed while enforcing RequireUpperBoundDeps. The error(s) are [
Require upper bound dependencies error for org.checkerframework:checker-qual:3.12.0 paths to dependency are:
+-org.janusgraph:janusgraph-dist:1.0.0-SNAPSHOT
  +-org.apache.tinkerpop:hadoop-gremlin:3.5.4
    +-com.google.guava:guava:31.1-jre (managed) <-- com.google.guava:guava:16.0.1
      +-org.checkerframework:checker-qual:3.12.0
and
+-org.janusgraph:janusgraph-dist:1.0.0-SNAPSHOT
  +-org.apache.tinkerpop:gremlin-groovy:3.5.4
    +-com.github.ben-manes.caffeine:caffeine:2.9.3 (managed) <-- com.github.ben-manes.caffeine:caffeine:2.3.1
      +-org.checkerframework:checker-qual:3.19.0

@ministat
Copy link
Contributor Author

@porunov Thanks for you comments, I have updated my patch.

@porunov porunov added this to the Release v1.0.0 milestone Aug 30, 2022
@ministat ministat force-pushed the vertex_cache_by_caffeine_cache branch from 11f130f to d838d08 Compare August 30, 2022 08:38
@porunov
Copy link
Member

porunov commented Aug 30, 2022

@ministat I fixed HBase tests issue in the latest commit in master and v0.6 branches. Would you be able to rebase your branch against the latest master commit please to ensure that all tests pass?
I.e.

git remote add upstream https://github.com/JanusGraph/janusgraph
git fetch upstream master
git rebase upstream/master
git push -f

@porunov
Copy link
Member

porunov commented Aug 30, 2022

@ministat it also looks like the benchmark class is often stuck in the first or second iteration for long time. I'm not sure but it could be flaky. I was waiting for 10 minutes for the second iteration to pass but it didn't finish. Sometimes it hangs on the warmup iteration. Do you know what is a correct way to run the benchmark you included?

I.e.

# JMH version: 1.35
# VM version: JDK 1.8.0_345, OpenJDK 64-Bit Server VM, 25.345-b01
# VM invoker: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.345.b01-1.fc36.x86_64/jre/bin/java
# VM options: <none>
# Blackhole mode: full + dont-inline hint (auto-detected, use -Djmh.blackhole.autoDetect=false to disable)
# Warmup: 2 iterations, 1 s each
# Measurement: 5 iterations, 5 s each
# Timeout: 10 min per iteration
# Threads: 8 threads, will synchronize iterations
# Benchmark mode: Average time, time/op
# Benchmark: org.janusgraph.VertexCacheBenchmark.run
# Parameters: (cacheType = guava)

# Run progress: 0.00% complete, ETA 00:00:54
# Fork: 1 of 1
# Warmup Iteration   1: 0.050 ±(99.9%) 0.262 ms/op
# Warmup Iteration   2: 0.002 ±(99.9%) 0.001 ms/op
Iteration   1: 

30 minutes later - nothing changed. Iteration 1 is still running. No timeouts are thrown. Very strange.

Update: I did recompile the project and the issue was somehow resolved. Below are my benchmarks.

# JMH version: 1.35
# VM version: JDK 1.8.0_345, OpenJDK 64-Bit Server VM, 25.345-b01
# VM invoker: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.345.b01-1.fc36.x86_64/jre/bin/java
# VM options: <none>
# Blackhole mode: full + dont-inline hint (auto-detected, use -Djmh.blackhole.autoDetect=false to disable)
# Warmup: 2 iterations, 1 s each
# Measurement: 5 iterations, 5 s each
# Timeout: 10 min per iteration
# Threads: 8 threads, will synchronize iterations
# Benchmark mode: Average time, time/op
# Benchmark: org.janusgraph.VertexCacheBenchmark.run
# Parameters: (cacheType = guava)

# Run progress: 0.00% complete, ETA 00:00:54
# Fork: 1 of 1
# Warmup Iteration   1: 0.007 ±(99.9%) 0.028 ms/op
# Warmup Iteration   2: 0.002 ±(99.9%) 0.001 ms/op
Iteration   1: 0.007 ±(99.9%) 0.030 ms/op
Iteration   2: 0.002 ±(99.9%) 0.001 ms/op
Iteration   3: 0.002 ±(99.9%) 0.001 ms/op
Iteration   4: 0.002 ±(99.9%) 0.001 ms/op
Iteration   5: 0.002 ±(99.9%) 0.001 ms/op


Result "org.janusgraph.VertexCacheBenchmark.run":
  0.003 ±(99.9%) 0.009 ms/op [Average]
  (min, avg, max) = (0.002, 0.003, 0.007), stdev = 0.002
  CI (99.9%): [≈ 0, 0.012] (assumes normal distribution)


# JMH version: 1.35
# VM version: JDK 1.8.0_345, OpenJDK 64-Bit Server VM, 25.345-b01
# VM invoker: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.345.b01-1.fc36.x86_64/jre/bin/java
# VM options: <none>
# Blackhole mode: full + dont-inline hint (auto-detected, use -Djmh.blackhole.autoDetect=false to disable)
# Warmup: 2 iterations, 1 s each
# Measurement: 5 iterations, 5 s each
# Timeout: 10 min per iteration
# Threads: 8 threads, will synchronize iterations
# Benchmark mode: Average time, time/op
# Benchmark: org.janusgraph.VertexCacheBenchmark.run
# Parameters: (cacheType = caffeine)

# Run progress: 50.00% complete, ETA 00:00:35
# Fork: 1 of 1
# Warmup Iteration   1: ≈ 10⁻⁴ ms/op
# Warmup Iteration   2: ≈ 10⁻⁴ ms/op
Iteration   1: ≈ 10⁻⁴ ms/op
Iteration   2: ≈ 10⁻⁴ ms/op
Iteration   3: ≈ 10⁻⁴ ms/op
Iteration   4: ≈ 10⁻⁴ ms/op
Iteration   5: ≈ 10⁻⁴ ms/op


Result "org.janusgraph.VertexCacheBenchmark.run":
  ≈ 10⁻⁴ ms/op


# Run complete. Total time: 00:01:04

Running Caffeine before Guava produces the same results.
Thus, I confirm that Caffeine 2.9.3 is much faster then Guava 31.1-jre.

Copy link
Member

@porunov porunov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you @ministat !
The PR looks good to me but I still suggest to rebase it against the latest master commit just in case (described here).

@ministat ministat force-pushed the vertex_cache_by_caffeine_cache branch from d838d08 to f79bdea Compare August 30, 2022 14:31
@ministat
Copy link
Contributor Author

@porunov, I have rebased per your suggestion.
For the benchmark, I run it through idea firstly. In order to run it in cmd line, I copied the idea's java classpath when it was running, pasted the long classpath into a file and run it again. I got the same perf results. I did not see hang in my test.

@porunov
Copy link
Member

porunov commented Aug 30, 2022

@porunov, I have rebased per your suggestion. For the benchmark, I run it through idea firstly. In order to run it in cmd line, I copied the idea's java classpath when it was running, pasted the long classpath into a file and run it again. I got the same perf results. I did not see hang in my test.

Thanks! Now to merge this PR we need to either wait for another commiter to approve this PR or wait 7 days to merge this PR with lazy consensus.

@ministat
Copy link
Contributor Author

ministat commented Aug 30, 2022

@porunov I found the build "mvn clean package" failed in any janusgraph-xxx folder, for example, janusgraph-core.
Before my CI, the build is successful. I'm still investigating. Do you have any suggestion?

~/Work/OpenSource/ministat_janusgraph/janusgraph-core @ LM-SHC-16507917 (hongjizhang) 
| => mvn clean package
[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------< org.janusgraph:janusgraph-core >-------------------
[INFO] Building JanusGraph-Core: Core Library for JanusGraph 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.2.0:clean (default-clean) @ janusgraph-core ---
[INFO] Deleting /Users/hongjizhang/Work/OpenSource/ministat_janusgraph/janusgraph-core/target
[INFO] 
[INFO] --- maven-enforcer-plugin:3.0.0:enforce (enforce-dependency-convergence) @ janusgraph-core ---
[WARNING] 
Dependency convergence error for org.checkerframework:checker-qual:jar:3.12.0:compile paths to dependency are:
+-org.janusgraph:janusgraph-core:jar:1.0.0-SNAPSHOT
  +-org.janusgraph:janusgraph-driver:jar:1.0.0-SNAPSHOT:compile
    +-com.google.guava:guava:jar:31.1-jre:compile
      +-org.checkerframework:checker-qual:jar:3.12.0:compile
and
+-org.janusgraph:janusgraph-core:jar:1.0.0-SNAPSHOT
  +-com.github.ben-manes.caffeine:caffeine:jar:2.9.3:compile
    +-org.checkerframework:checker-qual:jar:3.19.0:compile

[WARNING] Rule 1: org.apache.maven.plugins.enforcer.DependencyConvergence failed with message:
Failed while enforcing releasability. See above detailed error message.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.278 s
[INFO] Finished at: 2022-08-30T23:13:27+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.0.0:enforce (enforce-dependency-convergence) on project janusgraph-core: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

@ministat
Copy link
Contributor Author

After I "mvn install -DskipTests" from the root, the "mvn clean package" from janusgraph-core is successful. So, I think the previous failure is caused by referencing the wrong library.

@porunov
Copy link
Member

porunov commented Aug 30, 2022

I see that in janusgraph-driver we still are using checker-qual:3.12.0 which is provided by guava but it rest of the places we use checker-qual:3.19.0 which is provided by caffeine. I would suggest excluding this dependency from guava which is in janusgraph-driver and adding checker-qual:3.19.0 explicitly to the pom.xml. That way we will sure that all JanusGraph components depend on the same checker-qual version.

@li-boxuan
Copy link
Member

li-boxuan commented Aug 30, 2022

I would suggest excluding this dependency from guava which is in janusgraph-driver and adding checker-qual:3.19.0 explicitly to the pom.xml

I think we should add checker-qual:3.19.0 to the <dependencyManagement> section in root pom.xml. We don't want to introduce this dependency explicitly since JanusGraph is not using it directly.

Copy link
Member

@li-boxuan li-boxuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! I just have some nitpicks:

@@ -319,7 +319,7 @@ public void close() {
config.getVertexCacheSize(), effectiveVertexCacheSize, MIN_VERTEX_CACHE_SIZE);
}

vertexCache = new GuavaVertexCache(effectiveVertexCacheSize,concurrencyLevel,config.getDirtyVertexSize());
vertexCache = new CaffeineVertexCache(effectiveVertexCacheSize,config.getDirtyVertexSize());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also remove GuavaVertexCache class since it's not being used anymore?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand it is used in the benchmark test class. I guess we could move that class into testing module then

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can remove that class with the benchmark test class in the follow up PRs but I'm OK either way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think it's better to leave the benchmark test class in this PR for historical reasons. We can move GuavaVertexCache to test module and then later after the full transition to Caffeine cache is done we can remove those test classes with the benchmark classes. It's just good if those benchmark classes are in git history

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

later after the full transition to Caffeine cache is done we can remove those test classes with the benchmark classes

That sounds good to me!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree to leave GuavaVertexCache there. I'm ok to compose several following PRs to clean it up.
Meanwhile, I found there are some other Guava cache, like https://github.com/JanusGraph/janusgraph/blob/master/janusgraph-core/src/main/java/org/janusgraph/graphdb/transaction/subquerycache/GuavaSubqueryCache.java, and it is supposed to be replaced by Caffeine cache also, but I have not yet benchmark it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree to leave GuavaVertexCache there. I'm ok to compose several following PRs to clean it up. Meanwhile, I found there are some other Guava cache, like https://github.com/JanusGraph/janusgraph/blob/master/janusgraph-core/src/main/java/org/janusgraph/graphdb/transaction/subquerycache/GuavaSubqueryCache.java, and it is supposed to be replaced by Caffeine cache also, but I have not yet benchmark it.

There are 8 caches in JanusGraph actually and all of them need to be replaced by Caffeine (not in the current PR but in follow up PRs). I posted those places here: #871 (comment)

@ministat ministat force-pushed the vertex_cache_by_caffeine_cache branch from f79bdea to e94d940 Compare August 31, 2022 05:32
Copy link
Member

@li-boxuan li-boxuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat! I am okay with the failing codecov.

@ministat ministat force-pushed the vertex_cache_by_caffeine_cache branch from e94d940 to 9a22a1a Compare August 31, 2022 14:50
@porunov porunov merged commit c30c707 into JanusGraph:master Aug 31, 2022
porunov added a commit to porunov/janusgraph that referenced this pull request Aug 31, 2022
This is a follow-up commit to commit 9a22a1a

Move the rest (7) caches from Guava implementation to Caffeine implementation

This commit also removes a previously added Benchmark class with the obsolate GuavaVertexCache.class. The benchmark is provided in the next GitHub PR: JanusGraph#3188 which shows that Caffeine has better performance characteristics in all scenarious.

ConcurencyLevel is not provided for cache implementation. The reason for this can be found by the following link https://groups.google.com/g/guava-discuss/c/BnoN9q9fDgw/m/6kF6H2aLAgAJ

Related to JanusGraph#3188 and JanusGraph#3185

Partially related to JanusGraph#2033

Fixes JanusGraph#871
porunov added a commit to porunov/janusgraph that referenced this pull request Aug 31, 2022
This is a follow-up commit to commit 9a22a1a

Move the rest (7) caches from Guava implementation to Caffeine implementation

This commit also removes a previously added Benchmark class with the obsolate GuavaVertexCache.class. The benchmark is provided in the next GitHub PR: JanusGraph#3188 which shows that Caffeine has better performance characteristics in all scenarious.

ConcurencyLevel is not provided for cache implementation. The reason for this can be found by the following link https://groups.google.com/g/guava-discuss/c/BnoN9q9fDgw/m/6kF6H2aLAgAJ

Related to JanusGraph#3188 and JanusGraph#3185

Partially related to JanusGraph#2033

Fixes JanusGraph#871

Signed-off-by: Oleksandr Porunov <[email protected]>
porunov added a commit to porunov/janusgraph that referenced this pull request Aug 31, 2022
This is a follow-up commit to the 9a22a1a commit

Migrates the rest 7 caches from Guava implementation to Caffeine implementation

This commit also removes a previously added Benchmark class with the obsolate GuavaVertexCache.class. The benchmark is provided in the next GitHub PR: JanusGraph#3188 which shows that Caffeine has better performance characteristics in all scenarious.

ConcurencyLevel is not provided for the cache implementation anymore. The reason for this can be found by the following link https://groups.google.com/g/guava-discuss/c/BnoN9q9fDgw/m/6kF6H2aLAgAJ

Related to JanusGraph#3188 and JanusGraph#3185

Partially related to JanusGraph#2033

Fixes JanusGraph#871

Signed-off-by: Oleksandr Porunov <[email protected]>
porunov added a commit that referenced this pull request Sep 1, 2022
This is a follow-up commit to the 9a22a1a commit

Migrates the rest 7 caches from Guava implementation to Caffeine implementation

This commit also removes a previously added Benchmark class with the obsolate GuavaVertexCache.class. The benchmark is provided in the next GitHub PR: #3188 which shows that Caffeine has better performance characteristics in all scenarious.

ConcurencyLevel is not provided for the cache implementation anymore. The reason for this can be found by the following link https://groups.google.com/g/guava-discuss/c/BnoN9q9fDgw/m/6kF6H2aLAgAJ

Related to #3188 and #3185

Partially related to #2033

Fixes #871

Signed-off-by: Oleksandr Porunov <[email protected]>
private static final Logger log =
LoggerFactory.getLogger(CaffeineVertexCache.class);

private final ConcurrentMap<Long, InternalVertex> volatileVertices;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caffeine has special feature for avoid this extra field - ben-manes/caffeine#264

Implementation could be looks like https://gist.github.com/mad/9119f48812000a03dea16c7485c621fc

@ministat @porunov

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caffeine has special feature for avoid this extra field - ben-manes/caffeine#264

Implementation could be looks like https://gist.github.com/mad/9119f48812000a03dea16c7485c621fc

@ministat @porunov

That's interesting! I would prefer refactoring this class to eliminate this extra field as you proposed. That said, as it is a performance related part of the code we should probably execute benhmarking for any improvement we make here, just to make sure we don't have a regression. Other than that your proposal is much cleaner, so that's great.
Should we open a separate ticket to track this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, a related transitioning PR which replaces other Guava caches with Caffeine cache is: #3198
After that transitioning is merged I believe we need to refactor CaffeineVertexCache.java and ExpirationKCVSCache.java.

porunov added a commit that referenced this pull request Sep 22, 2022
This is a follow-up commit to the 9a22a1a commit

Migrates the rest 7 caches from Guava implementation to Caffeine implementation

This commit also removes a previously added Benchmark class with the obsolate GuavaVertexCache.class. The benchmark is provided in the next GitHub PR: #3188 which shows that Caffeine has better performance characteristics in all scenarious.

ConcurencyLevel is not provided for the cache implementation anymore. The reason for this can be found by the following link https://groups.google.com/g/guava-discuss/c/BnoN9q9fDgw/m/6kF6H2aLAgAJ

Related to #3188 and #3185

Partially related to #2033

Fixes #871

Signed-off-by: Oleksandr Porunov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: external Externally-managed CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants