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

Shareable executors #616

Merged
merged 16 commits into from
Mar 5, 2020
Merged

Conversation

mikkokar
Copy link
Contributor

@mikkokar mikkokar commented Feb 12, 2020

Summary

This PR allows end users to declare named executors (or threads) and share them between different Styx objects.

The executors only work with the new HostProxy and HttpServer objects. The old proxy and admin servers, and the old Styx Client, which are being phased out, still use the old clientWorkerThreadsCount, workerThreadsCount, and bossThreadsCount settings.

Configuration

The executors are declared in the executors block at the top-level of Styx configuration file:

executors:
  server:
    type: NettyExecutor
    config:
      threads: 4
      namePattern: "Styx-Server-Worker" 

The executor can be shared by other objects:

routing:
  originA:
    type: HostProxy
    config:
        ...
        executor: "server"

servers:
  https:
    type: HttpServer:
    config:
        ...
        executor: "server"

The top level yaml configuration follows the schema:

optional("executors", map(routingObject())),

Where routingObject is the familiar type/config/tags triple. The NettyExecutor object follows the schema:

    val SCHEMA = SchemaDsl.`object`(
            SchemaDsl.field("threads", SchemaDsl.integer()),
            SchemaDsl.field("namePattern", SchemaDsl.string())
    )

Styx is started with 3 "global" executors:

  • Styx-Client-Global-Worker, StyxHttpServer-Global-Worker, StyxHttpServer-Global-Boss. The routing objects will use them unless some other are specified by executor field. Consequently these names are reserved. Styx will always make sure that default global executors are available.

  • You can override the default global executor settings by specifying that reserved name in the executor configuration. For example, the following configuration will change the thread names for global server worker thread:

executors:
  StyxHttpServer-Global-Worker:
    type: NettyExecutor
    config:
      threads: 4
      namePattern: "styx-worker" 

Add a new executor field to YamlFileConfigurationService configuration. To specify the executor for the created HostProxy objects. When executor field is absent, it should use the default global executor.

@mikkokar mikkokar force-pushed the shareable-executors branch 3 times, most recently from 3c6ee49 to a1e372a Compare February 13, 2020 15:47
@mikkokar mikkokar marked this pull request as ready for review February 14, 2020 08:02
@@ -70,7 +72,11 @@ private NettyExecutor(EventLoopGroup eventLoopGroup,
}

public void shut() {
eventLoopGroup.shutdownGracefully();
try {
eventLoopGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS).await(5000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we wait here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi. It does wait for shutdownGracefully to come back.

Or do you refer to the quietPeriod setting? But we never really supported a graceful shutdown properly. Yet. I think we need to implement that on a "styx level".

The reason for immediate quiet and grace period is to avoid excessive waiting in functional test suite.

However I do think, going forward, we need to add timeout controls and a shutdown future to this API. Perhaps that should be a next increment, providing that the work is completed before the Styx 1.1 release. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The executors will only ever be closed when styx shuts. Therefore any shutdown future, etc doesn't really matter at the moment as the JVM is going to shut anyway. I would revisit this code if or once we'll allow consumers to shut injected executors.

try {
eventLoopGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS).await(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is clearing the interrupted flag, we've discussed previously it might not be the best option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. A good catch :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

*
* @return Styx service instance
*/
NettyExecutor create(String name, JsonNode configuration);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we try not to not pass a JsonNode here? It seems we keep propagating our Yaml based config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code follows the idiomatic fashion of creating styx objects from yaml/json nodes. Sadly the styx object model relies entirely on yaml and/or JsonNode based configuration.

I have created a a proof of concept that lifts this restriction. Check the details in PR: #609 (Remove old application router).

Till then, it needs to stay in this "idiomatic" form.

@@ -65,7 +66,7 @@ class YamlFileConfigurationServiceTest : FunSpec() {
try {
action(service)
} finally {
service.stop().join()
service.stop().get(2, SECONDS)
Copy link
Contributor

Choose a reason for hiding this comment

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

This could throw several exceptions here... makes me think we might want to implement Autocloseable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean, for the StyxService?

Copy link
Contributor

@chrisgresty chrisgresty left a comment

Choose a reason for hiding this comment

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

Just a couple of minor suggestiions.

@mikkokar mikkokar merged commit 1ed4ace into ExpediaGroup:master Mar 5, 2020
@mikkokar mikkokar deleted the shareable-executors branch March 5, 2020 11:22
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