-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(all):name thread pools #5425
feat(all):name thread pools #5425
Conversation
Executors.newSingleThreadScheduledExecutor( | ||
new ThreadFactoryBuilder().setNameFormat("db-stats-thread-%d").build()); | ||
|
||
private final String esName = "db-stats"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be static?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For singleton, there should be no need.
@@ -983,11 +983,13 @@ public Pair<Boolean, byte[]> execute(byte[] rawData) { | |||
public static class BatchValidateSign extends PrecompiledContract { | |||
|
|||
private static final ExecutorService workers; | |||
private static final String workersName = "validate-sign-contract"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this managed by ExecutorServiceManager?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, do you have any good ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we can just move the excutors name and the construction into ExecutorServiceManager, then the lifecycle and all the executors is controlled in ExecutorServiceManager , a certain executor shall be obtained by using a name(may be obtained by spring injection).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread pool shutdown is better controlled by the service, not the manager but this one is a special case, so maybe it can be done this way.
04e11f8
to
ecb622f
Compare
@@ -102,7 +103,7 @@ private void check(PeerConnection peer, TransactionsMessage msg) throws P2pExcep | |||
private void handleSmartContract() { | |||
smartContractExecutor.scheduleWithFixedDelay(() -> { | |||
try { | |||
while (queue.size() < MAX_SMART_CONTRACT_SUBMIT_SIZE) { | |||
while (queue.size() < MAX_SMART_CONTRACT_SUBMIT_SIZE && smartContractQueue.size() > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add this logic, if the queue has no elements, it will enter an infinite loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TrxEvent event = smartContractQueue.take();
Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.
@@ -102,7 +103,7 @@ private void check(PeerConnection peer, TransactionsMessage msg) throws P2pExcep | |||
private void handleSmartContract() { | |||
smartContractExecutor.scheduleWithFixedDelay(() -> { | |||
try { | |||
while (queue.size() < MAX_SMART_CONTRACT_SUBMIT_SIZE) { | |||
while (queue.size() < MAX_SMART_CONTRACT_SUBMIT_SIZE && smartContractQueue.size() > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try not to change the original logic, if it is a bug, it is recommended to submit a pr separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wubin01 , As explained above, smartContractExecutor.shutdown()
-> ExecutorServiceManager.shutdownAndAwaitTermination(smartContractExecutor, smartEsName)
if queue is empty, will block 60s
@@ -117,18 +116,6 @@ public void init() { | |||
exitThread.start(); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not adjust exitThread to SingleThreadExecutor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exitThread
will only run once
, when it receives the exit signal LockSupport.unpark(exitThread)
then System.exit(1)
, otherwise it blocks in here LockSupport.park()
, unlike other single-thread that has while(true) logic.
ecb622f
to
d0b03ab
Compare
d0b03ab
to
c75f33b
Compare
close #5422 .