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

fix issues/1463 : Make default JUL-based logging asynchronous #3136

Merged
merged 12 commits into from
Jun 26, 2023
Merged

fix issues/1463 : Make default JUL-based logging asynchronous #3136

merged 12 commits into from
Jun 26, 2023

Conversation

karl-sy
Copy link
Contributor

@karl-sy karl-sy commented Jun 1, 2023

Describe what this PR does / why we need it

Make default JUL-based logging asynchronous

Does this pull request fix one issue?

Fixes #1463

Describe how you did it

use java.util.concurrent.Executor, submit the log task into single thread.

Describe how to verify it

Special notes for reviews

@CLAassistant
Copy link

CLAassistant commented Jun 1, 2023

CLA assistant check
All committers have signed the CLA.

@sczyh30 sczyh30 added the area/logging Issues or PRs related to logging of Sentinel label Jun 1, 2023
@sczyh30
Copy link
Member

sczyh30 commented Jun 1, 2023

Hi, could you please sign the CLA here: https://cla-assistant.io/alibaba/Sentinel?pullRequest=3136

@sczyh30 sczyh30 requested a review from LearningGp June 1, 2023 12:59
@karl-sy
Copy link
Contributor Author

karl-sy commented Jun 2, 2023

add asynchronous test cases

@sczyh30 sczyh30 added the to-review To review label Jun 2, 2023
@@ -42,6 +47,9 @@ class ConsoleHandler extends Handler {
* A Handler which publishes log records to System.err.
*/
private StreamHandler stderrHandler;
@SuppressWarnings("PMD.ThreadPoolCreationRule")
Copy link
Member

Choose a reason for hiding this comment

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

You have to follow the Java code guidelines rather than skip it with @SuppressWarnings. The queue should be bounded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

has deleted

@@ -34,6 +39,10 @@ public SimpleDateFormat initialValue() {
}
};

@SuppressWarnings("PMD.ThreadPoolCreationRule")
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

has deleted

@@ -42,6 +47,9 @@ class ConsoleHandler extends Handler {
* A Handler which publishes log records to System.err.
*/
private StreamHandler stderrHandler;
@SuppressWarnings("PMD.ThreadPoolCreationRule")
private final ExecutorService executor = Executors.newSingleThreadExecutor(
new NamedThreadFactory("sentinel-log-executor", true));
Copy link
Member

Choose a reason for hiding this comment

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

You may need to refine the thread name so that we could distinguish the actual type of the logging (e.g. to file or to console).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

has renamed

@@ -79,6 +89,12 @@ public void flush() {

@Override
public void close() throws SecurityException {
executor.shutdown();
try {
executor.awaitTermination(3, TimeUnit.SECONDS);
Copy link
Member

Choose a reason for hiding this comment

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

Should we block and wait for termination here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

has deleted

@karl-sy karl-sy requested a review from sczyh30 June 6, 2023 12:01
Copy link
Member

@sczyh30 sczyh30 left a comment

Choose a reason for hiding this comment

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

The test cases could be improved later.

Copy link
Member

@sczyh30 sczyh30 left a comment

Choose a reason for hiding this comment

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

LGTM

@LearningGp LearningGp merged commit a64e818 into alibaba:master Jun 26, 2023
@LearningGp LearningGp removed the to-review To review label Jun 26, 2023
@sczyh30
Copy link
Member

sczyh30 commented Jun 26, 2023

Thanks for contributing!

LearningGp pushed a commit that referenced this pull request Dec 28, 2023
* fix issues/1463 : Make default JUL-based logging asynchronous
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/logging Issues or PRs related to logging of Sentinel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make default JUL-based logging asynchronous
4 participants