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 timer for recieving closeok, force close socket after a while #538

Closed
wants to merge 7 commits into from

Conversation

kickster97
Copy link
Member

No description provided.

@github-actions
Copy link

github-actions bot commented Jun 28, 2023

Main benchmark
'Average publish rate: 354126.3 msgs/s'
'Average consume rate: 354235.9 msgs/s'

PR benchmark
'Average publish rate: 354165.3 msgs/s'
'Average consume rate: 352251.6 msgs/s'

Keep in mind, these numbers are not representative of LavinMQ's peak performance.
It is rather an indication of how the changes of this pull request affects the performance of the main branch.

src/lavinmq/client/client.cr Outdated Show resolved Hide resolved
src/lavinmq/client/client.cr Outdated Show resolved Hide resolved
src/lavinmq/client/client.cr Outdated Show resolved Hide resolved
@kickster97 kickster97 marked this pull request as ready for review July 7, 2023 07:09
@kickster97 kickster97 requested a review from carlhoerberg July 7, 2023 07:13
@@ -143,6 +144,10 @@ module LavinMQ
if @running
process_frame(frame)
else
if (RoughTime.monotonic - @closeok_timer) > 5.seconds
Copy link
Member

Choose a reason for hiding this comment

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

this only works if the client still sends frames, but imagine a client that just consumes but doesn't properly send the CloseOk frame, eg. because it's busy with other things.. One possibility is to start a new fiber when we close the client, that sleeps 5s, checks if the connection is still open and then force closes it.

Copy link
Member

Choose a reason for hiding this comment

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

The down side is of course that if we closed 1M connections, and thus spawn 1M new fibers, that can be very memory intensive..

Copy link
Member

Choose a reason for hiding this comment

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

or we set a read_timeout on the socket when we try to gracefully close the client, so the read_loop will raise an TimeoutError if the client is silent.

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 think my last commit adds it in the way you're thinking, not sure how to test it easily

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 this if-statement isn't needed now with the read_timeout set? Instead we can check if @running == false, log something about timeout and break the loop? (cleanup and close_socket is always done thanks to the ensure block).

@kickster97 kickster97 closed this May 13, 2024
@kickster97 kickster97 deleted the closeok_timer branch May 31, 2024 11:57
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.

3 participants