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

Issue #204: Fix high CPU utilization after disconnects / connection losses #206

Merged

Conversation

Sebbo94BY
Copy link
Collaborator

@Sebbo94BY Sebbo94BY commented Aug 15, 2023

Changes:

  • Do not automatically close the connection when blocking=0 (non-blocking mode)
  • Properly exit loops after disconnects / connection losses

Before (without this change):

  • Aborting an e. g. TeamSpeak bot script resulted most of the time in a stuck script, which never finished / exited
  • Loosing the connection to the TeamSpeak server resulted most of the time in an endless loop, which caused a lot of disk I/O: pselect6(13, [12], [], [], {tv_sec=10, tv_nsec=0}, NULL) = 1 (in [12], left {tv_sec=9, tv_nsec=999998860}) (see https://linux.die.net/man/2/pselect6)
  • PHP script caused a very high CPU utilization (95-130 % on a single core system)

After (with this change):

  • Aborting an e. g. TeamSpeak bot script properly finishes / exits the script immediately (NOT stuck anymore)
  • Loosing the connection to the TeamSpeak server properly finishes / exits the script immediately (NO endless loop anymore and thus no disk I/O anymore)
  • PHP script does NOT cause any high CPU utilization anymore

Closes #204

@Sebbo94BY Sebbo94BY force-pushed the Issue-204-Exit-loop-on-disconnect branch from b3d0ec5 to bb830fd Compare August 15, 2023 20:18
@Sebbo94BY Sebbo94BY marked this pull request as draft August 15, 2023 20:27
@Sebbo94BY Sebbo94BY force-pushed the Issue-204-Exit-loop-on-disconnect branch 2 times, most recently from f476083 to 19e2e7e Compare August 16, 2023 01:51
Sebi94nbg added 2 commits August 16, 2023 22:08
This change should help to exit stuck loops, when the library is not connected to the remote server anymore.

- Fixes the existing `isConnected()` function to properly return TRUE or FALSE
- Adds a PHPUnit test for the `isConnected()` function
- Adds the connection status as condition to loops in order to abort, when it disconnected
When connected with `blocking=0` (non-blocking mode), the PHP script usually wants to stay connected, so the library shouldn't automatically disconnect it all the time. Instead, the user needs to manually disconnect.
@Sebbo94BY Sebbo94BY force-pushed the Issue-204-Exit-loop-on-disconnect branch from 19e2e7e to c8e8cfe Compare August 16, 2023 20:09
@Sebbo94BY Sebbo94BY changed the title Issue #204: Exit loops when disconnected Issue #204: Fix high CPU utilization after disconnects / connection losses Aug 16, 2023
@Sebbo94BY Sebbo94BY marked this pull request as ready for review August 16, 2023 20:28
@Sebbo94BY Sebbo94BY merged commit cd05928 into planetteamspeak:dev Aug 16, 2023
4 checks passed
@Sebbo94BY Sebbo94BY deleted the Issue-204-Exit-loop-on-disconnect branch August 16, 2023 20:29
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

1 participant