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

feat(all):name thread pools #5425

Merged
merged 13 commits into from
Aug 30, 2023

Conversation

halibobo1205
Copy link
Contributor

close #5422 .

Executors.newSingleThreadScheduledExecutor(
new ThreadFactoryBuilder().setNameFormat("db-stats-thread-%d").build());

private final String esName = "db-stats";
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be static?

Copy link
Contributor Author

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.

@halibobo1205 halibobo1205 self-assigned this Aug 17, 2023
@@ -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";
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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).

Copy link
Contributor Author

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.

@@ -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) {
Copy link
Contributor

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.

Copy link
Contributor Author

@halibobo1205 halibobo1205 Aug 21, 2023

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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();
}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@halibobo1205 halibobo1205 merged commit 03e903e into tronprotocol:develop Aug 30, 2023
2 checks passed
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.

Organize all ThreadExecutors with explicit name and time-wait shutdown
5 participants