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

Add ability to limit outgoing message rate #142

Open
wants to merge 10 commits into
base: dev-version-3
Choose a base branch
from

Conversation

cordwelt
Copy link
Contributor

@cordwelt cordwelt commented Jul 7, 2022

No description provided.

import java.util.concurrent.TimeUnit.SECONDS
import java.util.concurrent.locks.LockSupport

class RateLimiter(rate: Int) {

Choose a reason for hiding this comment

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

This implementation isn't thread-safe, and we should remind about this if we want to use more than one thread for AMQP

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can make it thread-safe

@@ -94,7 +95,7 @@ public void stop() throws IOException {
private void handle(String consumerTag, RawMessageBatch messageBatch) {
for (RawMessage protoMessage : messageBatch.getMessagesList()) {
try {
rateLimiter.acquire();
while (!rateLimiter.tryAcquire()) LockSupport.parkNanos(1_000);

Choose a reason for hiding this comment

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

Let's encapsulate the cycle in the tryAcquire function

build.gradle Outdated Show resolved Hide resolved
Co-authored-by: Nikita Smirnov <[email protected]>
@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@@ -1 +1,5 @@
<<<<<<< HEAD

Choose a reason for hiding this comment

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

Resolve conflicts

@Nikita-Smirnov-Exactpro Nikita-Smirnov-Exactpro deleted the branch dev-version-3 October 11, 2023 07:28
@Nikita-Smirnov-Exactpro Nikita-Smirnov-Exactpro changed the base branch from dev to dev-version-3 October 11, 2023 07:31
@Nikita-Smirnov-Exactpro Nikita-Smirnov-Exactpro deleted the branch dev-version-3 October 11, 2023 07:34
@Nikita-Smirnov-Exactpro Nikita-Smirnov-Exactpro changed the base branch from dev-version-3-tmp to dev October 11, 2023 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants