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

[ISSUE #2856]Adjust the use of thread pools (naming module) #3136

Merged
merged 1 commit into from
Jun 28, 2020

Conversation

wangweizZZ
Copy link
Collaborator

@wangweizZZ wangweizZZ commented Jun 21, 2020

Please do not create a Pull Request without creating an issue first.

What is the purpose of the change

#2856

Brief changelog

  1. Unified naming module thread pool usage

Verifying this change

XXXX

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

@wangweizZZ
Copy link
Collaborator Author

wangweizZZ commented Jun 21, 2020

submit the part first and then modify the rest , please help to review this pr @chuntaojun @KomachiSion @zongtanghu

* @author gagharv
*/
@SuppressWarnings({"checkstyle:indentation", "PMD.ThreadPoolCreationRule"})
public class NamingExecutor {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would chain calls be better?

for example

NamingExecutor.mysqlCheckExecutor().xxx

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This will cause the thread pool to be exposed to the outside but the user can call shutdown by himself.

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe this idea should implemented wrapped for ThreadPoolExecutor

Copy link
Collaborator

@KomachiSion KomachiSion left a comment

Choose a reason for hiding this comment

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

I think this implementation is too complicated.
The GlobalExecutor is a logic wrapper for Executors, we only need to put the creating and managing down to ExecutorPoolManager.
Also, you can enhance the class name and method name of GlobalExecutor to make it more readlable.

Change-Id: I626179bd9ee8e852d9d51787950ad80744ec71cd
@wangweizZZ
Copy link
Collaborator Author

@KomachiSion how about this

@zongtanghu
Copy link
Collaborator

Plesase help to reivew this pr together, @chuntaojun @KomachiSion , thanks very much.

Comment on lines -47 to -67


private AtomicInteger connectIdGenerator = new AtomicInteger(0);


private Map<Integer, StreamObserver<Resources>> connnections = new ConcurrentHashMap<>(16);


private Map<String, Resource> resourceMap = new ConcurrentHashMap<>(16);


private Map<String, String> checksumMap = new ConcurrentHashMap<>(16);


private static final String SERVICE_NAME_SPLITTER = "nacos";


private static final String MESSAGE_TYPE_URL = "type.googleapis.com/istio.networking.v1alpha3.ServiceEntry";


private static final long MCP_PUSH_PERIOD_MILLISECONDS = 10000L;


@Autowired
private ServiceManager serviceManager;


@Autowired
private IstioConfig istioConfig;

Copy link
Collaborator

Choose a reason for hiding this comment

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

New code style?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, code format

private static final ScheduledExecutorService NAMING_TIMER_EXECUTOR = ExecutorFactory.Managed
.newScheduledExecutorService(ClassUtils.getCanonicalName(NamingApp.class),
Runtime.getRuntime().availableProcessors() * 2,
new NameThreadFactory("com.alibaba.nacos.naming.timer"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use public final static String variable to represent the const value "com.alibaba.nacos.naming.timer" is better? The same is as below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If set to public, there is no need to provide a method

@KomachiSion KomachiSion added this to the 1.3.1 milestone Jun 28, 2020
@KomachiSion KomachiSion merged commit 3f145e6 into alibaba:develop Jun 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants