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

Add a flushBuffer API #380

Merged
merged 2 commits into from
Dec 16, 2020
Merged

Add a flushBuffer API #380

merged 2 commits into from
Dec 16, 2020

Conversation

ColinSullivan1
Copy link
Member

@ColinSullivan1 ColinSullivan1 commented Dec 15, 2020

This PR adds a flush buffer API to flush the underlying socket (through the socket output stream).

I did use a synchronized API on the connection writer because research seemed to indicate the best performance with a smaller number of threads - at least in older versions of java. It also fit well with the current architecture since there is no connection level locking. Instead publish synchronization resolves around the message writer and message queue. There's a small chance when publishing and immediately doing a flushBuffer, the flushBuffer will beat the message writer, but without major surgery I'm not sure how to fix that.

Regardless, I was able to exceed capacity of the underlying message queue unless I flushed in the test itself so performance doesn't seem to be impacted much.

CC /@scottf @RichardHightower

Signed-off-by: Colin Sullivan colin@synadia.com

Signed-off-by: Colin Sullivan <colin@synadia.com>
Copy link
Contributor

@matthiashanel matthiashanel left a comment

Choose a reason for hiding this comment

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

I'd raise the underlying exception.

try {
dataPort.flush();
} catch (Exception e) {
// NOOP
Copy link
Contributor

Choose a reason for hiding this comment

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

pass it along? technically you don't know if it got flushed

@@ -29,6 +29,9 @@

import io.nats.client.Options;

/**
* This class is not theadsafe. Caller must ensure thread safety.
*/
public class SocketDataPort implements DataPort {
Copy link
Contributor

Choose a reason for hiding this comment

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

private class?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure why it was public, perhaps for testing. Good point though. I might take a pass through the classes outside of this PR.

/**
* Immediately flushes the underlying connection buffer if the connection is valid.
*/
public void flushBuffer();
Copy link
Contributor

Choose a reason for hiding this comment

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

throws IOException?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was on the fence, but yeah - probably good to let the user handle that.

Copy link
Member

@wallyqs wallyqs left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@sasbury sasbury left a comment

Choose a reason for hiding this comment

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

looks ok to me, haven't been in Java for a bit, my only concern is that it works with all the NIO work someone was doing but if this is rebased on that 👍

Signed-off-by: Colin Sullivan <colin@synadia.com>
@ColinSullivan1 ColinSullivan1 merged commit aa12f96 into master Dec 16, 2020
Copy link
Contributor

@matthiashanel matthiashanel left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants