forked from apache/pinot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds a new SPI that can be extended to support new executor services. By default 2 executors are provided: cached, the default, which is a wrapper on top of Executors.newCachedThreadPool. fixed, which is a wrapper on top of Executors.newFixedThreadPool. Right now only org.apache.pinot.query.runtime.QueryRunner uses this SPI.
- Loading branch information
Showing
14 changed files
with
267 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
pinot-common/src/main/java/org/apache/pinot/common/utils/CachedExecutorServicePlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pinot.common.utils; | ||
|
||
import com.google.auto.service.AutoService; | ||
import java.util.concurrent.Executors; | ||
import org.apache.pinot.spi.executor.ExecutorServicePlugin; | ||
import org.apache.pinot.spi.executor.ExecutorServiceProvider; | ||
|
||
|
||
/** | ||
* This is the plugin for the cached executor service. | ||
* | ||
* The provider included in this plugin creates cached thread pools, which are the recommended executor service for | ||
* cases where the tasks are short-lived and not CPU bound. | ||
* | ||
* If that is not the case, this executor may create a large number of threads that will be competing for CPU resources, | ||
* which may lead to performance degradation and even system instability. | ||
* In that case {@link FixedExecutorServicePlugin} could be used, but it may need changes to the code to avoid | ||
* deadlocks. Deployments using Java 21 or above could consider using a virtual thread executor service plugin. | ||
* | ||
* @see org.apache.pinot.spi.executor.ExecutorServiceUtils | ||
*/ | ||
@AutoService(ExecutorServicePlugin.class) | ||
public class CachedExecutorServicePlugin implements ExecutorServicePlugin { | ||
@Override | ||
public String id() { | ||
return "cached"; | ||
} | ||
|
||
@Override | ||
public ExecutorServiceProvider provider() { | ||
return (conf, confPrefix, baseName) -> Executors.newCachedThreadPool(new NamedThreadFactory(baseName)); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
pinot-common/src/main/java/org/apache/pinot/common/utils/FixedExecutorServicePlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pinot.common.utils; | ||
|
||
import com.google.auto.service.AutoService; | ||
import java.util.concurrent.Executors; | ||
import org.apache.pinot.spi.executor.ExecutorServicePlugin; | ||
import org.apache.pinot.spi.executor.ExecutorServiceProvider; | ||
import org.apache.pinot.spi.utils.CommonConstants; | ||
|
||
|
||
/** | ||
* This is the plugin for the fixed executor service. | ||
* | ||
* The fixed executor service plugin creates a new fixed thread pool. | ||
* The number of threads is defined in the configuration with the {@code <prefix>.numThreads} property. | ||
* This executor service is recommended for cases where the tasks are long-lived or CPU bound, but it may need changes | ||
* to the code to avoid deadlocks. | ||
* | ||
* @see org.apache.pinot.spi.executor.ExecutorServiceUtils | ||
*/ | ||
@AutoService(ExecutorServicePlugin.class) | ||
public class FixedExecutorServicePlugin implements ExecutorServicePlugin { | ||
@Override | ||
public String id() { | ||
return "fixed"; | ||
} | ||
|
||
@Override | ||
public ExecutorServiceProvider provider() { | ||
return (conf, confPrefix, baseName) -> { | ||
String defaultFixedThreadsStr = conf.getProperty( | ||
CommonConstants.CONFIG_OF_EXECUTORS_FIXED_NUM_THREADS, CommonConstants.DEFAULT_EXECUTORS_FIXED_NUM_THREADS); | ||
int defaultFixedThreads = Integer.parseInt(defaultFixedThreadsStr); | ||
if (defaultFixedThreads < 0) { | ||
defaultFixedThreads = Runtime.getRuntime().availableProcessors(); | ||
} | ||
int numThreads = conf.getProperty(confPrefix + ".numThreads", defaultFixedThreads); | ||
return Executors.newFixedThreadPool(numThreads, new NamedThreadFactory(baseName)); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
pinot-spi/src/main/java/org/apache/pinot/spi/executor/ExecutorServicePlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pinot.spi.executor; | ||
|
||
public interface ExecutorServicePlugin { | ||
|
||
/** | ||
* An id that identifies this specific provider. | ||
* <p> | ||
* This id is used to select the provider in the configuration. | ||
*/ | ||
String id(); | ||
|
||
/** | ||
* Returns the provider that will create the {@link java.util.concurrent.ExecutorService} instances. | ||
*/ | ||
ExecutorServiceProvider provider(); | ||
} |
38 changes: 38 additions & 0 deletions
38
pinot-spi/src/main/java/org/apache/pinot/spi/executor/ExecutorServiceProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pinot.spi.executor; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import org.apache.pinot.spi.env.PinotConfiguration; | ||
|
||
|
||
/** | ||
* A provider for {@link ExecutorService} instances. | ||
*/ | ||
public interface ExecutorServiceProvider { | ||
/** | ||
* Creates a new {@link ExecutorService} instance. | ||
* | ||
* @param conf the configuration to use | ||
* @param confPrefix the prefix to use for the configuration | ||
* @param baseName the base name for the threads. A prefix that all threads will share. | ||
* @return a new {@link ExecutorService} instance | ||
*/ | ||
ExecutorService create(PinotConfiguration conf, String confPrefix, String baseName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.