[Improvement] Set heartBeatExecutorService as daemon thread by smallzhongfeng · Pull Request #121 · apache/uniffle · GitHub
Skip to content

[Improvement] Set heartBeatExecutorService as daemon thread#121

Merged
roryqi merged 7 commits into
apache:masterfrom
smallzhongfeng:heartBeatExecutorService-daemon
Aug 3, 2022
Merged

[Improvement] Set heartBeatExecutorService as daemon thread#121
roryqi merged 7 commits into
apache:masterfrom
smallzhongfeng:heartBeatExecutorService-daemon

Conversation

@smallzhongfeng

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

When the main thread of the shuffleServer exits, the heartbeat thread should exit as well.

Why are the changes needed?

More formal.

Does this PR introduce any user-facing change?

No

How was this patch tested?

No need.

@smallzhongfeng

Copy link
Copy Markdown
Contributor Author

@codecov-commenter

codecov-commenter commented Aug 3, 2022

Copy link
Copy Markdown

Codecov Report

Merging #121 (4cd39ca) into master (fce4bb6) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##             master     #121      +/-   ##
============================================
- Coverage     57.17%   57.16%   -0.01%     
+ Complexity     1201     1200       -1     
============================================
  Files           150      150              
  Lines          8177     8178       +1     
  Branches        773      773              
============================================
  Hits           4675     4675              
  Misses         3257     3257              
- Partials        245      246       +1     
Impacted Files Coverage Δ
...ava/org/apache/uniffle/common/web/JettyServer.java 56.25% <100.00%> (-0.68%) ⬇️
...a/org/apache/uniffle/server/RegisterHeartBeat.java 44.64% <100.00%> (+2.05%) ⬆️
...storage/handler/impl/DataSkippableReadHandler.java 81.25% <0.00%> (-3.13%) ⬇️
.../apache/uniffle/coordinator/ClientConfManager.java 91.54% <0.00%> (-1.41%) ⬇️
...va/org/apache/uniffle/common/util/ThreadUtils.java 50.00% <0.00%> (+50.00%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@roryqi

roryqi commented Aug 3, 2022

Copy link
Copy Markdown
Contributor

Why do we need this patch?

@smallzhongfeng

Copy link
Copy Markdown
Contributor Author

I'm not sure whether the main thread of the shuffleServer will exit unexpectedly, but is it meaningful to set the heartbeat scheduling thread as the daemon thread.

@roryqi

roryqi commented Aug 3, 2022

Copy link
Copy Markdown
Contributor

I'm not sure whether the main thread of the shuffleServer will exit unexpectedly, but is it meaningful to set the heartbeat scheduling thread as the daemon thread.

Ok, have you checked similar problems in other code in our project? Could you fix them together?

@smallzhongfeng

Copy link
Copy Markdown
Contributor Author

The same as ExecutorService executor = Executors.newSingleThreadExecutor(); I think this one needs to be set to a daemon thread as well. What do you think?@jerqi

@roryqi

roryqi commented Aug 3, 2022

Copy link
Copy Markdown
Contributor

The same as ExecutorService executor = Executors.newSingleThreadExecutor(); I think this one needs to be set to a daemon thread as well. What do you think?@jerqi

I think we should check all types ExecutorService. A similar pr ba47aa0

@smallzhongfeng

Copy link
Copy Markdown
Contributor Author

Reference pr you metioned, I set all unnecessary user threads as daemon.


protected void sendCommit() {
ExecutorService executor = Executors.newSingleThreadExecutor();
ExecutorService executor = Executors.newSingleThreadExecutor(ThreadUtils.getThreadFactory("bufferManagerSend-%d"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a temporary thread pool. I think it's unnecessary to be a daemon thread pool.WDYT?

@smallzhongfeng smallzhongfeng Aug 3, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think I made a mistake here, but I think a better way would have been to generate this executor at this object initialization. @jerqi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

MEMORY_LOCALFILE and MEMROY_HDFS don't call commit operation, so we use a temporary thread pool.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it.

@VisibleForTesting
protected void sendCommit() {
ExecutorService executor = Executors.newSingleThreadExecutor();
ExecutorService executor = Executors.newSingleThreadExecutor(ThreadUtils.getThreadFactory("sendCommit-%d"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a temporary thread pool. I think it's unnecessary to be a daemon thread pool.WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree with you here, there really is no need for a daemon thread.

@Test
public void testServerMetricsConcurrently() throws Exception {
ExecutorService executorService = Executors.newFixedThreadPool(3);
ExecutorService executorService = Executors.newCachedThreadPool(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a temporary thread pool. I think it's unnecessary to be a daemon thread pool.WDYT?

CountDownLatch countDownLatch = new CountDownLatch(storageBasePaths.length);
AtomicInteger successCount = new AtomicInteger();
ExecutorService executorService = Executors.newCachedThreadPool();
ExecutorService executorService = Executors.newCachedThreadPool(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a temporary thread pool. I think it's unnecessary to be a daemon thread pool.WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Would it be better to create the thread pool when the LocalStorageManager is initialized.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We only use this thread pool to delete the files once when the server start. I think it's no need.

@smallzhongfeng smallzhongfeng requested a review from roryqi August 3, 2022 13:26
private final LocalStorageChecker checker;
private List<LocalStorage> unCorruptedStorages = Lists.newArrayList();
private final Set<String> corruptedStorages = Sets.newConcurrentHashSet();
private final ExecutorService executorService = Executors.newCachedThreadPool(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We only use this thread pool to delete the files once when the server start. I think it's no need.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated.

smallzhongfeng added 2 commits August 3, 2022 21:58

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we modify this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

IIRC, a cachedThreadPool should be faster if the number of threads started is known though this is just a test class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why these thread numbers are needed here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We hope use multi-thread to call some methods, usually thread pool has specific number threads, more tasks is summited, more threads will be created util the thread number reach the max value. I guess that we just ensure multi-thread call the methods, I would like not to modify here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it.

@roryqi roryqi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks @smallzhongfeng

@roryqi roryqi merged commit fd8ccdd into apache:master Aug 3, 2022
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