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

Client: Add the ability to disable stats #67

Merged
merged 7 commits into from
May 29, 2019

Conversation

jentfoo
Copy link
Member

@jentfoo jentfoo commented May 27, 2019

These stats are fairly lightweight, but do incur some memory and computational overhead.
This change allows them to be disabled on a per-connection basis either as a setting change on the SocketExecutor, or on the Client itself.

I would in the future like to add additional stats, but have not arrived at what would be good to include. Pool based stats might make sense, but those can be passed in when constructing the SocketExecutor. Maybe stats around delays around notifying the selector and the selector waking up? However I was unsure precisely how that would be useful. @lwahlmeier let me know if you have thoughts around that, or this PR in general.

jentfoo added 2 commits May 27, 2019 14:28
These stats are fairly lightweight, but do incur some memory and computational overhead.
This change allows them to be disabled on a per-connection basis either as a setting change on the `SocketExecutor`, or on the `Client` itself.
@jentfoo jentfoo requested a review from lwahlmeier May 27, 2019 22:05
…dScheduler instance

This is to allow stats to be collected on the underline scheduler if desired.
In addition SingleThreadSocketExecutor was transitioned to manually constructing a single thread (rather than a pool), to reduce overhead.  It also will do a `join` on the stop to ensure that the stop has completed before returning.
ThreadedSocketExecutor removed unnecssary variable
perConnectionStatsEnabled = enabled;
}

protected void recordReadStatst(int size) {
Copy link
Member

Choose a reason for hiding this comment

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

I assume this is supposed to be recordReadStats

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing out, fixed now

}

protected void addReadAmount(int size) {
public void setPerConnectionStatsEnabled(boolean enabled) {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure what you think about this, but it seems like we should loop through all clients and enable or disable them when this changes.

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 considered looping through, it would require locking to be 100%, so I was thinking that this is probably good enough. Let me know your thoughts

Copy link
Member

Choose a reason for hiding this comment

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

You could do it with schedule on the selector threads, not sure if its worth it or not, just an idea.

Copy link
Member Author

Choose a reason for hiding this comment

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

For now I say we leave it, I can't imagine changing this while clients are active is likely

Copy link
Member

@lwahlmeier lwahlmeier left a comment

Choose a reason for hiding this comment

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

All in all, I like the changes. All small performance improvements but that can add up. Left a few comments but lgtm

@jentfoo
Copy link
Member Author

jentfoo commented May 28, 2019

@lwahlmeier Any ideas on how we can get other stats from the selector? For example any ideas on how we could get signal about possible network congestion, or other conditions outside of pool execution time?

@lwahlmeier
Copy link
Member

@lwahlmeier Any ideas on how we can get other stats from the selector? For example any ideas on how we could get signal about possible network congestion, or other conditions outside of pool execution time?

Yeah there are some options, keeping track of total bytes pending write VS amount written over a period of time, it is a little tricky to know if its backed up or not. Maybe just how many/what % of clients are waiting for Write to the socket. I also feel like getting stats on the selector thread loop time it takes the selector to process clients could be another indication.

jentfoo added 2 commits May 27, 2019 21:59
…Bytes

This metric helps you know across all clients how backed up you are either consuming data into the application (likely cpu or otherwise bound by the application), or write bound (network or remote side being the bottleneck).
@jentfoo
Copy link
Member Author

jentfoo commented May 28, 2019

@lwahlmeier Yeah, I was originally thinking something like "set write interests, then time how long till we can write". I am not sure if that would really help or not though.

So instead, for now I kept it simple, adding to the SocketExecutor a way to total up the pending bytes across all the Clients. What do you think of this API? Docs seem accurate?

I wonder if these pending byte stats should be part of the stats object they already return. I played with that, I think API wise it's a little cleaner since all the stats are more located together. However code structure wise is slightly not as pretty. Let me know your preference if you like this way I can go ahead and merge, if you want stats more co-located...I can deprecate Client.get(Read|Write)BufferSize and instead add the functions as part of SimpleByteStats (probably abstract definition there).

Thanks for taking a look, I want to make sure you are happy with this and I believe these stat improvements will be useful to me.

@lwahlmeier
Copy link
Member

Hum, moving the get read/write size to the stats could make sense, it does feel a little weird to me to have those as changing stats when the SimpleByteStats object is returned, but it is no different then the read/write rates/totals. If you think it make sense I say go for it.

Client stats for write round trip times could be pretty nice. It could also show congestion or other issues, though I dont like the idea of hitting the clock that much in high load situations so it would have to be disableable.

I am good with this the way it is for now, but if you want to do the above let me know and I will look through the changes.

@jentfoo
Copy link
Member Author

jentfoo commented May 29, 2019

I filed issue #68 so we can consider the API changes later for 5.0. I would like to make the API changes, but am frustrated by not being able to keep things as efficient as they are with the current API. Feel free to drop thoughts on that issue, but going to just roll with this for now.

@jentfoo jentfoo merged commit 42cede9 into threadly:master May 29, 2019
@jentfoo jentfoo deleted the statChanges branch May 29, 2019 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants