This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fury.git
The following commit(s) were added to refs/heads/main by this push:
new f1651d6e fix(java): return fury to pooled which get from (#1697)
f1651d6e is described below
commit f1651d6ed8fa389dd19ad766021e74869bf59d04
Author: Shuchang Li <[email protected]>
AuthorDate: Sat Jun 22 00:47:57 2024 +0800
fix(java): return fury to pooled which get from (#1697)
<!--
**Thanks for contributing to Fury.**
**If this is your first time opening a PR on fury, you can refer to
[CONTRIBUTING.md](https://github.com/apache/fury/blob/main/CONTRIBUTING.md).**
Contribution Checklist
- The **Apache Fury (incubating)** community has restrictions on the
naming of pr titles. You can also find instructions in
[CONTRIBUTING.md](https://github.com/apache/fury/blob/main/CONTRIBUTING.md).
- Fury has a strong focus on performance. If the PR you submit will have
an impact on performance, please benchmark it first and provide the
benchmark result here.
-->
## What does this PR do?
<!-- Describe the purpose of this PR. -->
incase of pooledCache expired from cache, and fury will return to
another pooledCache.
so we save pooledCache instead of get from cache.
## Related issues
<!--
Is there any related issue? Please attach here.
- #xxxx0
- #xxxx1
- #xxxx2
-->
## Does this PR introduce any user-facing change?
<!--
If any user-facing interface changes, please [open an
issue](https://github.com/apache/fury/issues/new/choose) describing the
need to do so and update the document if necessary.
-->
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
<!--
When the PR has an impact on performance (if you don't know whether the
PR will have an impact on performance, you can submit the PR first, and
if it will have impact on performance, the code reviewer will explain
it), be sure to attach a benchmark data here.
-->
---
.../apache/fury/pool/ClassLoaderFuryPooled.java | 1 +
.../apache/fury/pool/FuryPooledObjectFactory.java | 23 +++-------------------
.../java/org/apache/fury/pool/ThreadPoolFury.java | 15 ++++++++++++--
3 files changed, 17 insertions(+), 22 deletions(-)
diff --git
a/java/fury-core/src/main/java/org/apache/fury/pool/ClassLoaderFuryPooled.java
b/java/fury-core/src/main/java/org/apache/fury/pool/ClassLoaderFuryPooled.java
index 7f02fe02..c1ad2ada 100644
---
a/java/fury-core/src/main/java/org/apache/fury/pool/ClassLoaderFuryPooled.java
+++
b/java/fury-core/src/main/java/org/apache/fury/pool/ClassLoaderFuryPooled.java
@@ -109,6 +109,7 @@ public class ClassLoaderFuryPooled {
furyCondition.signalAll();
} catch (Exception e) {
LOG.error(e.getMessage(), e);
+ throw new RuntimeException(e);
} finally {
lock.unlock();
}
diff --git
a/java/fury-core/src/main/java/org/apache/fury/pool/FuryPooledObjectFactory.java
b/java/fury-core/src/main/java/org/apache/fury/pool/FuryPooledObjectFactory.java
index 872fd459..56033bf5 100644
---
a/java/fury-core/src/main/java/org/apache/fury/pool/FuryPooledObjectFactory.java
+++
b/java/fury-core/src/main/java/org/apache/fury/pool/FuryPooledObjectFactory.java
@@ -81,33 +81,16 @@ public class FuryPooledObjectFactory {
CacheBuilder.newBuilder().expireAfterAccess(expireTime,
timeUnit).build();
}
- public Fury getFury() {
+ public ClassLoaderFuryPooled getPooledCache() {
try {
ClassLoader classLoader = classLoaderLocal.get();
ClassLoaderFuryPooled classLoaderFuryPooled =
classLoaderFuryPooledCache.getIfPresent(classLoader);
if (classLoaderFuryPooled == null) {
// double check cache
- ClassLoaderFuryPooled cache = getOrAddCache(classLoader);
- return cache.getFury();
+ return getOrAddCache(classLoader);
}
- return classLoaderFuryPooled.getFury();
- } catch (Exception e) {
- LOG.error(e.getMessage(), e);
- throw new RuntimeException(e);
- }
- }
-
- public void returnFury(Fury fury) {
- try {
- ClassLoader classLoader = classLoaderLocal.get();
- ClassLoaderFuryPooled classLoaderFuryPooled =
- classLoaderFuryPooledCache.getIfPresent(classLoader);
- if (classLoaderFuryPooled == null) {
- // ifPresent will be cleared when cache expire 30's
- return;
- }
- classLoaderFuryPooled.returnFury(fury);
+ return classLoaderFuryPooled;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
diff --git
a/java/fury-core/src/main/java/org/apache/fury/pool/ThreadPoolFury.java
b/java/fury-core/src/main/java/org/apache/fury/pool/ThreadPoolFury.java
index f1c4bd6b..da163ccf 100644
--- a/java/fury-core/src/main/java/org/apache/fury/pool/ThreadPoolFury.java
+++ b/java/fury-core/src/main/java/org/apache/fury/pool/ThreadPoolFury.java
@@ -29,6 +29,8 @@ import org.apache.fury.AbstractThreadSafeFury;
import org.apache.fury.Fury;
import org.apache.fury.io.FuryInputStream;
import org.apache.fury.io.FuryReadableChannel;
+import org.apache.fury.logging.Logger;
+import org.apache.fury.logging.LoggerFactory;
import org.apache.fury.memory.MemoryBuffer;
import org.apache.fury.memory.MemoryUtils;
import org.apache.fury.serializer.BufferCallback;
@@ -37,6 +39,8 @@ import org.apache.fury.util.LoaderBinding;
@ThreadSafe
public class ThreadPoolFury extends AbstractThreadSafeFury {
+ private static final Logger LOG =
LoggerFactory.getLogger(ThreadPoolFury.class);
+
private final FuryPooledObjectFactory furyPooledObjectFactory;
private Consumer<Fury> factoryCallback = f -> {};
@@ -67,12 +71,19 @@ public class ThreadPoolFury extends AbstractThreadSafeFury {
@Override
public <R> R execute(Function<Fury, R> action) {
+ ClassLoaderFuryPooled pooledCache = null;
Fury fury = null;
try {
- fury = furyPooledObjectFactory.getFury();
+ pooledCache = furyPooledObjectFactory.getPooledCache();
+ fury = pooledCache.getFury();
return action.apply(fury);
+ } catch (Exception e) {
+ LOG.error(e.getMessage(), e);
+ throw new RuntimeException(e);
} finally {
- furyPooledObjectFactory.returnFury(fury);
+ if (pooledCache != null) {
+ pooledCache.returnFury(fury);
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]