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

[SPARK-46698][CORE] Replace Timer with single thread scheduled executor for ConsoleProgressBar. #44701

Closed

Conversation

beliefer
Copy link
Contributor

@beliefer beliefer commented Jan 12, 2024

What changes were proposed in this pull request?

This PR propose to replace Timer with single thread scheduled executor for ConsoleProgressBar.

Why are the changes needed?

The javadoc recommends ScheduledThreadPoolExecutor instead of Timer.
屏幕快照 2024-01-12 下午12 47 57

This change based on the following two points.
System time sensitivity

Timer scheduling is based on the absolute time of the operating system and is sensitive to the operating system's time. Once the operating system's time changes, Timer scheduling is no longer precise.
The scheduled Thread Pool Executor scheduling is based on relative time and is not affected by changes in operating system time.

Are anomalies captured

Timer does not capture exceptions thrown by Timer Tasks, and in addition, Timer is single threaded. Once a scheduling task encounters an exception, the entire thread will terminate and other tasks that need to be scheduled will no longer be executed.
The scheduled Thread Pool Executor implements scheduling functions based on a thread pool. After a task throws an exception, other tasks can still execute normally.

Does this PR introduce any user-facing change?

'No'.

How was this patch tested?

Manual tests.

Was this patch authored or co-authored using generative AI tooling?

'No'.

@beliefer beliefer force-pushed the replace-timer-with-scheduled-executor branch from ac01d8c to 44a3d92 Compare January 12, 2024 04:49
@beliefer beliefer changed the title [WIP][CORE] Replace Timer with single thread scheduled executor for ConsoleProgressBar. [SPARK-46698][CORE] Replace Timer with single thread scheduled executor for ConsoleProgressBar. Jan 12, 2024
@beliefer
Copy link
Contributor Author

ping @srowen @dongjoon-hyun @LuciferYang

Copy link
Contributor

@LuciferYang LuciferYang left a comment

Choose a reason for hiding this comment

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

+1 from myside

@srowen
Copy link
Member

srowen commented Jan 12, 2024

Looks OK, just rerun tests

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

+1, LGTM.

@dongjoon-hyun
Copy link
Member

Merged to master. I verified manually the console progress bar. It looks working without any issue as expected.

@beliefer
Copy link
Contributor Author

@dongjoon-hyun @srowen @LuciferYang Thank you!

jshmchenxi pushed a commit to jshmchenxi/spark that referenced this pull request Aug 31, 2024
…or for ConsoleProgressBar

### What changes were proposed in this pull request?
This PR propose to replace `Timer` with single thread scheduled executor for `ConsoleProgressBar`.

### Why are the changes needed?
The javadoc recommends `ScheduledThreadPoolExecutor` instead of `Timer`.
![屏幕快照 2024-01-12 下午12 47 57](https://github.com/apache/spark/assets/8486025/4fc5ed61-6bb9-4768-915a-ad919a067d04)

This change based on the following two points.
**System time sensitivity**

Timer scheduling is based on the absolute time of the operating system and is sensitive to the operating system's time. Once the operating system's time changes, Timer scheduling is no longer precise.
The scheduled Thread Pool Executor scheduling is based on relative time and is not affected by changes in operating system time.

**Are anomalies captured**

Timer does not capture exceptions thrown by Timer Tasks, and in addition, Timer is single threaded. Once a scheduling task encounters an exception, the entire thread will terminate and other tasks that need to be scheduled will no longer be executed.
The scheduled Thread Pool Executor implements scheduling functions based on a thread pool. After a task throws an exception, other tasks can still execute normally.

### Does this PR introduce _any_ user-facing change?
'No'.

### How was this patch tested?
Manual tests.

### Was this patch authored or co-authored using generative AI tooling?
'No'.

Closes apache#44701 from beliefer/replace-timer-with-scheduled-executor.

Authored-by: beliefer <beliefer@163.com>
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
(cherry picked from commit fc66576)
jshmchenxi pushed a commit to jshmchenxi/spark that referenced this pull request Sep 2, 2024
…or for ConsoleProgressBar

### What changes were proposed in this pull request?
This PR propose to replace `Timer` with single thread scheduled executor for `ConsoleProgressBar`.

### Why are the changes needed?
The javadoc recommends `ScheduledThreadPoolExecutor` instead of `Timer`.
![屏幕快照 2024-01-12 下午12 47 57](https://github.com/apache/spark/assets/8486025/4fc5ed61-6bb9-4768-915a-ad919a067d04)

This change based on the following two points.
**System time sensitivity**

Timer scheduling is based on the absolute time of the operating system and is sensitive to the operating system's time. Once the operating system's time changes, Timer scheduling is no longer precise.
The scheduled Thread Pool Executor scheduling is based on relative time and is not affected by changes in operating system time.

**Are anomalies captured**

Timer does not capture exceptions thrown by Timer Tasks, and in addition, Timer is single threaded. Once a scheduling task encounters an exception, the entire thread will terminate and other tasks that need to be scheduled will no longer be executed.
The scheduled Thread Pool Executor implements scheduling functions based on a thread pool. After a task throws an exception, other tasks can still execute normally.

### Does this PR introduce _any_ user-facing change?
'No'.

### How was this patch tested?
Manual tests.

### Was this patch authored or co-authored using generative AI tooling?
'No'.

Closes apache#44701 from beliefer/replace-timer-with-scheduled-executor.

Authored-by: beliefer <beliefer@163.com>
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
(cherry picked from commit fc66576)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants