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

Optimize server2 #163

Merged
merged 6 commits into from
Nov 27, 2024
Merged

Optimize server2 #163

merged 6 commits into from
Nov 27, 2024

Conversation

malloch
Copy link
Contributor

@malloch malloch commented Nov 12, 2024

Server code reorganization & consolidation, fixes some erroneous behaviour and hopefully makes future maintenance easier:

  • use lo_servers_wait internally for all calls to poll/select, i.e. with a 0 timeout for lo_server_recv. This removes a bunch of duplicate code
  • don't call poll/select again if we already know something was received
  • return an error (-1) from lo_server_wait and lo_servers_wait if returning early due to error rather than msg received or full timeout
  • do not return from lo_server_recv if a received message was queued for future dispatch
  • if a queued message is ready for dispatch, dispatch it rather than just queuing a new message and returning

Adds a configure/cmake option for disabling poll if desired since testing shows a substantial performance penalty for using this code path in liblo (possibly due to the alloca?). On MacOS/M2 Pro, the testspeed test in libmapper completes in ~4.3 seconds using the liblo poll path and ~2.6 seconds using select.

…server_recv as well. Fixed buggy behaviours in which handling a newly queued message would take precedence over dispatching an existing queued message with a lower timestamp, and in which undispatched messages would still cause lo_server_recv to return.
@malloch malloch marked this pull request as draft November 13, 2024 13:50
@radarsat1
Copy link
Owner

No objection here, if you want to take it out of draft I will merge it. (Although I find it very surprising that either poll or alloca would cause any latency.)

@malloch
Copy link
Contributor Author

malloch commented Nov 15, 2024

Apparently the slow poll is a BSD/MacOS thing, with the only solution to use kqueues instead: https://forums.developer.apple.com/forums/thread/764698

@malloch
Copy link
Contributor Author

malloch commented Nov 15, 2024

I have another upcoming commit to add to the PR then I will take it out of draft.

@malloch malloch marked this pull request as ready for review November 19, 2024 20:01
@malloch
Copy link
Contributor Author

malloch commented Nov 27, 2024

Pinging @radarsat1 – please let me know if you have any concerns about the PR or items to discuss!

@radarsat1 radarsat1 merged commit a3dc0cb into radarsat1:master Nov 27, 2024
4 checks passed
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.

2 participants