Comments (9)
I have copied the ByteArrayOutputStream into a new file and replaced the synchronized with the ReentrantLock. The synchronized blocks are 10x faster.
from jersey.
At first glance, adaptedOutput.write(buffer.toByteArray());
seems worse performance-wise as it is synchronized too and it creates a copy of the data buffer for each call. We should measure the performance and have the change for JDK 21+ only, if worse on JDK [8,20)
from jersey.
At first glance, adaptedOutput.write(buffer.toByteArray()); seems worse performance-wise as it is synchronized too
Yes, BufferedOutputStream.toByteArray() is synchronised , but it does not lead to the specific issue of carrier thread pinning, as there is no IO happening from with this sync block.
public synchronized byte[] toByteArray() {
return Arrays.copyOf(buf, count);
}
yes, It does make Array copy .
Looking further at the. stack snippet. in this scenario, the concrete type of "adaptedOutput" is of. type. "TracingObserver$TracingStreamOutputDelegate" .
Further, The BufferedOutputStream.write() is synchronized only when it is subclassed and not used directly.
https://github.com/openjdk/jdk/blob/890adb6410dab4606a4f26a942aed02fb2f55387/src/java.base/share/classes/java/io/BufferedOutputStream.java#L87
Stack Snippet
io.helidon.webserver.http1.Http1ServerResponse$BlockingOutputStream.write(Http1ServerResponse.java:585) io.helidon.webserver.http1.Http1ServerResponse$BlockingOutputStream.write(Http1ServerResponse.java:470) java.base/[java.io](http://java.io/).BufferedOutputStream.implWrite(BufferedOutputStream.java:217) java.base/[java.io](http://java.io/).BufferedOutputStream.write(BufferedOutputStream.java:200) io.helidon.webserver.http1.Http1ServerResponse$ClosingBufferedOutputStream.write(Http1ServerResponse.java:749) io.helidon.webserver.observe.tracing.TracingObserver$TracingStreamOutputDelegate.write(TracingObserver.java:525) java.base/[java.io](http://java.io/).ByteArrayOutputStream.writeTo(ByteArrayOutputStream.java:163) <== monitors:1 org.glassfish.jersey.message.internal.CommittingOutputStream.flushBuffer(CommittingOutputStream.java:278) org.glassfish.jersey.message.internal.CommittingOutputStream.commit(CommittingOutputStream.java:232)
from jersey.
Interesting test results, for buffer=ByteArrayOutputStream, adaptedOutput=FileOutputStream, 32MB written:
| JDK | Actual Method | Proposed Method |
| -------------------------------------------------------------- |
| 8 | 90ms | 98ms |
| 11 | 35ms | 40ms |
| 17 | 45ms | 50ms |
| 21 | 43ms | 48ms |
It looks like the proposed method is about 10% slowlier, no virtual threads. So we should have this just for virtual threads.
from jersey.
Perhaps a better solution is to have a ByteArrayOutputStream without synchronized blocks, with reentrant locks instead to avoid data copying.
from jersey.
#5629 Is for 2.x and 3.0, we should check for Thread#isVirtual in 3.1 and forward.
from jersey.
Keep open for 3.1
from jersey.
#5632 fixes the issue in 2.4.3.
Helidon 4.x. uses jersey 3.1.5
https://github.com/helidon-io/helidon/blob/main/dependencies/pom.xml
<version.lib.jersey>3.1.5</version.lib.jersey>
Which version of 3.1 would have this fix for Helidon to uptake?
from jersey.
The next one, 3.1.7
from jersey.
Related Issues (20)
- jersey-netty-connector - Cancelling the future returned by rx() client does not terminate the request HOT 4
- Project Loom/JDK 21 compatible HOT 8
- Inquiry about Jersey Project Licensing and Third-Party Content Usage HOT 7
- jersey 3.1 default exception mapper message interferes with setStatusOverSendError=true
- [Feature request] Configuration options for multipart requests (Jersey 3.1.x) HOT 8
- `UriRoutingContext` may not log tracing events
- Each HTTP request unnecessarily starts a new thread, resource leak. HOT 6
- HttpUrlConnector to support domain fronting HOT 2
- Jersey 3.1.6 release HOT 2
- Jersey 3.0.x has no working provider that support Java 17, PATCH, and multipart attachments HOT 3
- JdkConnector does not properly cleanup ERROR state connections HOT 3
- NettyConnector does not respect timeouts HOT 7
- CVE-2023-4043 for jersey-media-json-binding dependency (parsson-1.1.1) HOT 2
- Injection error when using a `DynamicFeature` HOT 3
- Possible NPE in RequestContextFilter when other Filters prioritized
- Jersey 3.1.7 release HOT 5
- Jersey 3.1.6 not closing request on Jetty earlyEOF HOT 3
- Connection is not stable (wrong detection if SSL context is configured) HOT 1
- Preserve whitespace in Content-Type header HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jersey.