Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Centralize alarm executor creation for Pub/Sub Lite (#565)
* fix: Set batching settings on SinglePartitionPublisher * fix: Centralize alarm executor creation for Pub/Sub Lite Also prevent creation of per-object thread pools which are largely unused and may prevent shutdown if not using daemon threads.
- Loading branch information
1 parent
5371c6c
commit 5f73967
Showing
9 changed files
with
109 additions
and
87 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
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
39 changes: 39 additions & 0 deletions
39
...d-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/wire/SystemExecutors.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,39 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed 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 com.google.cloud.pubsublite.internal.wire; | ||
|
||
import com.google.cloud.pubsublite.internal.Lazy; | ||
import com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
public class SystemExecutors { | ||
private SystemExecutors() {} | ||
|
||
public static ScheduledExecutorService newDaemonExecutor(String prefix) { | ||
return Executors.newScheduledThreadPool( | ||
Math.max(4, Runtime.getRuntime().availableProcessors()), | ||
new ThreadFactoryBuilder().setDaemon(true).setNameFormat(prefix + "-%d").build()); | ||
} | ||
|
||
private static final Lazy<ScheduledExecutorService> ALARM_EXECUTOR = | ||
new Lazy<>(() -> newDaemonExecutor("pubsub-lite-alarms")); | ||
// An executor for alarms. | ||
public static ScheduledExecutorService getAlarmExecutor() { | ||
return ALARM_EXECUTOR.get(); | ||
} | ||
} |
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