Skip to content

Add single-threaded mode #214

@N7Alpha

Description

@N7Alpha

This would entail adding an additional mode to juice_concurrency_t ... something like JUICE_CONCURRENCY_MODE_POLL_AGENT_DIRECTLY

Basically this would mean the user of libjuice would be in charge of polling the agent to get received packets

Here are some of the potential issues I'm aware of

  • If the user doesn't poll frequently enough the connection could die since Keep Alive packets won't be sent
  • Buffering UDP packets is now at the mercy of the OS/OS Socket Library. If you receive too much data packets might be purged... since protocols built on UDP have to tolerate lost packets anyway this probably isn't an issue, and if you know the type and amount of data you're sending like for my use case this isn't a problem.

Here are some benefits

  • Real-time friendlier code. You can get rid of all mutex contention. In theory you could get rid of mutex's altogether (for this mode) although refactoring that would probably be annoying and eliminating contention is practically just as good. My use case involves running emulated games on a background thread. You really don't want to get preempted if it can be avoided.
  • There is a nonnegligible amount of overhead caused by running an extra OS-Level thread. In a broadcast network this problem is exacerbated. I think it is intended JUICE_CONCURRENCY_MODE_POLL will solve this problem as well. After looking through the implementation though it seems like this behavior isn't implemented yet so the default mode always behaves like JUICE_CONCURRENCY_MODE_THREAD (I might be wrong about this)

I might be missing a few things here since my knowledge of networking is incomplete. If the only thing preventing this is something like the few potential issues I listed above then I think punting them to the user of libjuice is reasonable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions