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

Update_the_default_SubscriberDeliveryTaskCount #765

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

MENNAELMESALMY
Copy link

This pull request is meant to solve this issue #450.
The added test was tried against different numbers of SubscriberDeliveryTaskCount, it takes around ~500 ms to process, leaving it to 0 (as was the default before) takes more than 1000 ms ( ~7000ms).

@scottf
Copy link
Collaborator

scottf commented May 7, 2023

There are 2 reasons that #450 has been around so long and probably should have been closed.

  1. Making this change would actually not be backward compatible.
  2. The user can change this since it's an option.

I think this functionality would actually be best served by having one an full example and adding documentation, not by changing the default.

@MENNAELMESALMY
Copy link
Author

MENNAELMESALMY commented May 7, 2023

Hi @scottf
Can you tell me more what should be best demonstrated in the documentation example? I believe this is the current documentation and is generated from the comments in the code?
Also if it will be incompatible in some cases we could add a warning in the documentation so no one will set it to that value by mistake, can you provide more details on that?

@scottf
Copy link
Collaborator

scottf commented May 8, 2023

So by documentation I mean a full sample and probably stuff in the readme. We know the project could certainly use more docs.
My concern about backward compatibility is that the default behavior would change, but we could document this. I've reached out and asked someone else if they think this would be okay, I should hear back tomorrow.

@ColinSullivan1
Copy link
Member

Thanks for the contribution! I think the new default (1) is reasonable. This change would affect users who have a small number of subscribers and require extremely high throughput. This change should certainly be called out in release notes.

Minor fix in the doc, otherwise LGTM! Thanks!

Copy link
Member

@ColinSullivan1 ColinSullivan1 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@MENNAELMESALMY MENNAELMESALMY force-pushed the Update_the_default_SubscriberDeliveryTaskCount_issue_450 branch 3 times, most recently from 0c470a3 to d23577e Compare May 8, 2023 20:09
@scottf
Copy link
Collaborator

scottf commented May 8, 2023

@MENNA123MAHMOUD Can you please look at IntegrationTests.TestSubscriptions.TestAsyncSubscribersOnClose
This test is failing with the change. When I put the option back to zero, the test passes.

@scottf scottf modified the milestone: JetStream May 9, 2023
@MENNAELMESALMY
Copy link
Author

Hi @scottf
I looked into IntegrationTests.TestSubscriptions.TestAsyncSubscribersOnClose and it was failing with A task may only be disposed if it is in a completion state (RanToCompletion, Faulted or Canceled). .

            internal Channel<Msg> getChannel()
            {
                // simple round robin, adding Channels/Tasks as necessary.
                lock (pLock)
                {
                    if (current == maxTasks)
                        current = 0;

                    if (pList.Count == current)
                        pList.Add(new SubChannelProcessor(connection));

                    return pList[current++].Channel;
                }
            }

The SubChannelProcessor class was creating Tasks with no cancellation token so when the channel was disposed tasks was still not marked as completed hence the error. Sending a token and signaling with it the other tasks to cancel solves the issue.

@MENNAELMESALMY
Copy link
Author

However now this test IntegrationTests.TestBasic.TestUrlArgument is failing due to timeout connecting to Nats, it works fine locally on my laptop though and doesn't seem related to my change as it doesn't create any async subscribers for example.
Any ideas on how to approach this @scottf @ColinSullivan1

@scottf
Copy link
Collaborator

scottf commented May 14, 2023

@MENNA123MAHMOUD Don't worry about TestUrlArgument. Not sure why it fails intermittently, I've been looking into it, but like you , it works fine on my machine.

MENNAELMESALMY and others added 6 commits June 11, 2023 12:22
Signed-off-by: Menna Mahmoud <menna123mahmoud@gmail.com>
Co-authored-by: Christopher Watford <christopher.watford@gmail.com>
Signed-off-by: Menna Mahmoud <menna123mahmoud@gmail.com>
Signed-off-by: Menna Mahmoud <menna123mahmoud@gmail.com>
Signed-off-by: Menna Mahmoud <menna123mahmoud@gmail.com>
@MENNAELMESALMY MENNAELMESALMY force-pushed the Update_the_default_SubscriberDeliveryTaskCount_issue_450 branch from 6bf702e to 61c902d Compare June 11, 2023 11:26
@MENNAELMESALMY
Copy link
Author

Hi @ColinSullivan1 @scottf
Is there something I could help with to get this merged?

@scottf
Copy link
Collaborator

scottf commented Jun 11, 2023

@ColinSullivan1 I've been thinking about this a lot. I don't think we should change the default. The user can still change this because it's an option.
So remember multiple subscriptions are coming through the same channel. One behavior I noticed that delivery comes in bunches, which is simply how the server pushes messages to the client. But with multiple channels, this would all go in parallel. With a shared channel, one handler might get a bunch of messages, which they take time to handle and ack and that blocks the other handlers from getting their messages to work on.
This is not bad, but I think it should be a conscious choice to share the channel. This is what the java client does, give the developer to specify the "dispatcher" and whether subs share it.
At some point in the recent past, I actually started going down the dispatcher path for .net and would like to continue doing that.

@scottf
Copy link
Collaborator

scottf commented Jun 11, 2023

@MENNA123MAHMOUD So there is one change that I definitely want and that's the change to SubChannelProcessor where you added the cancellation token. Would it be possible to make a PR just for that? This will allow us to get the improvement in and then continue considering how to address the rest of the problem.

@scottf
Copy link
Collaborator

scottf commented Jun 11, 2023

Sorry one more note about sharing the channel. Since you setup a pool per connection, right now you would have to keep making connections to have different groups of subscribers in different channel pools.

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.

None yet

4 participants