-
Notifications
You must be signed in to change notification settings - Fork 498
[FLINK-33525] Move ImpulseSource to new Source API #950
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
Merged
afedulov
merged 6 commits into
apache:main
from
Poorvankbhatia:FLINK-33525-NewImpulseSource
Mar 10, 2025
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
618d50a
Move ImpulseSource to new Source API
Poorvankbhatia de5fb01
Added DataGeneratorSource to replace Impulse source.
Poorvankbhatia 0d2bd2d
Added a descriptive comment.
Poorvankbhatia eb8ef85
Corrected comment logic, based on the review.
Poorvankbhatia de713b7
Adjusted calculation based on comment.
Poorvankbhatia fabd090
Addressed comment
Poorvankbhatia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,20 +82,32 @@ public static void main(String[] args) throws Exception { | |
| * Creates an unbounded stream that continuously emits the constant value 42L. | ||
| * Flink's DataGeneratorSource with RateLimiterStrategy is used to control the emission rate. | ||
| * | ||
| * Rate Calculation: | ||
| * - samplingIntervalMs / 10 gives maxSleepTimeMs, which represents the interval between emissions. | ||
| * - To determine the number of records emitted per second: | ||
| * 1000 / maxSleepTimeMs | ||
| * Since 1000 ms equals 1 second, this formula calculates the emission rate. | ||
| * Emission Rate Logic: | ||
| * - The goal is to generate a fixed number of impulses per sampling interval. | ||
| * - `samplingIntervalMs` defines the duration of one sampling interval in milliseconds. | ||
| * - We define `IMPULSES_PER_SAMPLING_INTERVAL = 10`, meaning that for every sampling interval, | ||
| * exactly 10 impulses should be generated. | ||
| * | ||
| * Example: | ||
| * - If samplingIntervalMs = 1000 ms: | ||
| * maxSleepTimeMs = 100 ms | ||
| * - This results in: | ||
| * 1000 ms / 100 ms = 10 records per second. | ||
| * To calculate the total number of records emitted per second: | ||
| * 1. Determine how many sampling intervals fit within one second: | ||
| * samplingIntervalsPerSecond = 1000 / samplingIntervalMs; | ||
| * 2. Multiply this by the number of impulses per interval to get the total rate: | ||
| * impulsesPerSecond = IMPULSES_PER_SAMPLING_INTERVAL * samplingIntervalsPerSecond; | ||
| * | ||
| * RateLimiterStrategy.perSecond((double) 1000 / ((double) samplingIntervalMs / 10)) | ||
| * ensures this rate is maintained efficiently without blocking execution. | ||
| * Example Calculations: | ||
| * - If `samplingIntervalMs = 1000 ms`: | ||
| * - `samplingIntervalsPerSecond = 1000 / 1000 = 1` | ||
| * - `impulsesPerSecond = 10 * 1 = 10 records per second` | ||
| * - If `samplingIntervalMs = 500 ms`: | ||
| * - `samplingIntervalsPerSecond = 1000 / 500 = 2` | ||
| * - `impulsesPerSecond = 10 * 2 = 20 records per second` | ||
| * - If `samplingIntervalMs = 2000 ms`: | ||
| * - `samplingIntervalsPerSecond = 1000 / 2000 = 0.5` | ||
| * - `impulsesPerSecond = 10 * 0.5 = 5 records per second` | ||
| * | ||
| * This approach ensures that the number of records emitted dynamically scales | ||
|
||
| * based on the sampling interval while maintaining the target of 10 impulses per interval. | ||
| * RateLimiterStrategy internally distributes these emissions efficiently over time. | ||
| */ | ||
| DataStream<Long> stream = | ||
| env.fromSource( | ||
|
|
@@ -109,7 +121,7 @@ public static void main(String[] args) throws Exception { | |
| / 10)), // Controls rate | ||
| Types.LONG), | ||
| WatermarkStrategy.noWatermarks(), | ||
| "ImpulseSource (Using DataGeneratorSource)"); | ||
| "ImpulseSource"); | ||
|
|
||
| for (String load : taskLoads) { | ||
| double maxLoad = Double.parseDouble(load); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: either introduce this constant and use it in the calculations or use plain text in the comment.
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.
Added the constant.