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

Fix PARALLEL executorGroup to ensure sequential execution for single DiscoveryRequestStreamObserver #103

Open
MarcinFalkowski opened this issue Apr 10, 2020 · 0 comments

Comments

@MarcinFalkowski
Copy link
Contributor

Currently we use one ThreadPoolExecutor shared for all DiscoveryRequestStreamObservers as an ExecutorGroup: https://github.com/allegro/envoy-control/blob/master/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/ControlPlane.kt#L105
(only when corresponding property is set to PARALLEL, which is not the default)

This approach is not valid because it will lead to sending XDS responses out-of-order for given DiscoveryRequestStreamObserver.

We should switch our parallel ExecutorGroup implementation to multiple, single-threaded ThreadPoolExecutors. This way we will ensure that single DiscoveryRequestStreamObserver is running sequentially, but many DiscoveryRequestStreamObservers may run in parallel.

Implementation of such ExecutorGroup may look like this (not tested):

 class SequentialExecutorGroup(
    threads: Int,
    singleThreadedExecutorFactory: (Int) -> ExecutorService
) : ExecutorGroup {

    private val executors = (0 until threads).map(singleThreadedExecutorFactory)
    private val counter = AtomicInteger(0)

    override fun next(): Executor {

        val index = counter.getAndUpdate { c ->
            val next = c+1
            if (next >= executors.size) {
                0
            } else {
                next
            }
        }

        return executors[index]
    }
}
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

No branches or pull requests

1 participant