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

1.x: replay request coordination reduce overhead #3470

Merged
merged 1 commit into from
Jun 15, 2016

Conversation

akarnokd
Copy link
Member

Reported in #3469.

This change will make sure whenever a new subscriber arrives, the
request coordination doesn't scan every other subscriber unnecessary.
(They will trigger a manageRequests individually anyway).

Unfortunately, I can't make the subscription registration constant (via a HashSet) because that would slow down the dispatching loop (which is quite expensive to for-each over compared to a plain array).

Note also that this will likely conflict with #3454.

I get the following numbers with the program in #3469.

subscribing...
subscribed so far 10000; took 54ms to subscribe last 10000 at rate: 185185 per sec...
subscribed so far 20000; took 110ms to subscribe last 10000 at rate: 90909 per sec...
subscribed so far 30000; took 157ms to subscribe last 10000 at rate: 63694 per sec...
subscribed so far 40000; took 267ms to subscribe last 10000 at rate: 37453 per sec...
subscribed so far 50000; took 211ms to subscribe last 10000 at rate: 47393 per sec...
subscribed so far 60000; took 320ms to subscribe last 10000 at rate: 31250 per sec...
subscribed so far 70000; took 331ms to subscribe last 10000 at rate: 30211 per sec...
subscribed so far 80000; took 369ms to subscribe last 10000 at rate: 27100 per sec...
subscribed so far 90000; took 415ms to subscribe last 10000 at rate: 24096 per sec...
subscribed so far 100000; took 462ms to subscribe last 10000 at rate: 21645 per sec...
subscribed so far 110000; took 516ms to subscribe last 10000 at rate: 19379 per sec...
subscribed so far 120000; took 547ms to subscribe last 10000 at rate: 18281 per sec...
subscribed so far 130000; took 647ms to subscribe last 10000 at rate: 15455 per sec...
subscribed so far 140000; took 720ms to subscribe last 10000 at rate: 13888 per sec...
subscribed so far 150000; took 811ms to subscribe last 10000 at rate: 12330 per sec...
subscribed so far 160000; took 806ms to subscribe last 10000 at rate: 12406 per sec...
subscribed so far 170000; took 873ms to subscribe last 10000 at rate: 11454 per sec...
subscribed so far 180000; took 911ms to subscribe last 10000 at rate: 10976 per sec...
subscribed so far 190000; took 986ms to subscribe last 10000 at rate: 10141 per sec...
subscribed so far 200000; took 1003ms to subscribe last 10000 at rate: 9970 per sec...
subscribed so far 210000; took 1168ms to subscribe last 10000 at rate: 8561 per sec...
subscribed so far 220000; took 1213ms to subscribe last 10000 at rate: 8244 per sec...
subscribed so far 230000; took 1340ms to subscribe last 10000 at rate: 7462 per sec...
subscribed so far 240000; took 1314ms to subscribe last 10000 at rate: 7610 per sec...
subscribed so far 250000; took 1548ms to subscribe last 10000 at rate: 6459 per sec...
subscribed so far 260000; took 1372ms to subscribe last 10000 at rate: 7288 per sec...
subscribed so far 270000; took 1835ms to subscribe last 10000 at rate: 5449 per sec...
subscribed so far 280000; took 2087ms to subscribe last 10000 at rate: 4791 per sec...
subscribed so far 290000; took 1910ms to subscribe last 10000 at rate: 5235 per sec...
subscribed so far 300000; took 1966ms to subscribe last 10000 at rate: 5086 per sec...
unsubscribing...
unsubscribed so far 10000; took 1910ms to unsubscribe last 10000 at rate: 5235 per sec...
unsubscribed so far 20000; took 1782ms to unsubscribe last 10000 at rate: 5611 per sec...
unsubscribed so far 30000; took 1730ms to unsubscribe last 10000 at rate: 5780 per sec...
unsubscribed so far 40000; took 1593ms to unsubscribe last 10000 at rate: 6277 per sec...
unsubscribed so far 50000; took 1514ms to unsubscribe last 10000 at rate: 6605 per sec...
unsubscribed so far 60000; took 1468ms to unsubscribe last 10000 at rate: 6811 per sec...
unsubscribed so far 70000; took 1188ms to unsubscribe last 10000 at rate: 8417 per sec...
unsubscribed so far 80000; took 1234ms to unsubscribe last 10000 at rate: 8103 per sec...
unsubscribed so far 90000; took 1271ms to unsubscribe last 10000 at rate: 7867 per sec...
unsubscribed so far 100000; took 1358ms to unsubscribe last 10000 at rate: 7363 per sec...
unsubscribed so far 110000; took 1103ms to unsubscribe last 10000 at rate: 9066 per sec...
unsubscribed so far 120000; took 1100ms to unsubscribe last 10000 at rate: 9090 per sec...
unsubscribed so far 130000; took 990ms to unsubscribe last 10000 at rate: 10101 per sec...
unsubscribed so far 140000; took 953ms to unsubscribe last 10000 at rate: 10493 per sec...
unsubscribed so far 150000; took 854ms to unsubscribe last 10000 at rate: 11709 per sec...
unsubscribed so far 160000; took 789ms to unsubscribe last 10000 at rate: 12674 per sec...
unsubscribed so far 170000; took 779ms to unsubscribe last 10000 at rate: 12836 per sec...
unsubscribed so far 180000; took 624ms to unsubscribe last 10000 at rate: 16025 per sec...
unsubscribed so far 190000; took 634ms to unsubscribe last 10000 at rate: 15772 per sec...
unsubscribed so far 200000; took 514ms to unsubscribe last 10000 at rate: 19455 per sec...
unsubscribed so far 210000; took 411ms to unsubscribe last 10000 at rate: 24330 per sec...
unsubscribed so far 220000; took 373ms to unsubscribe last 10000 at rate: 26809 per sec...
unsubscribed so far 230000; took 337ms to unsubscribe last 10000 at rate: 29673 per sec...
unsubscribed so far 240000; took 286ms to unsubscribe last 10000 at rate: 34965 per sec...
unsubscribed so far 250000; took 234ms to unsubscribe last 10000 at rate: 42735 per sec...
unsubscribed so far 260000; took 222ms to unsubscribe last 10000 at rate: 45045 per sec...
unsubscribed so far 270000; took 159ms to unsubscribe last 10000 at rate: 62893 per sec...
unsubscribed so far 280000; took 96ms to unsubscribe last 10000 at rate: 104166 per sec...
unsubscribed so far 290000; took 63ms to unsubscribe last 10000 at rate: 158730 per sec...
unsubscribed so far 300000; took 31ms to unsubscribe last 10000 at rate: 322580 per sec...

@akarnokd
Copy link
Member Author

I've updated the code to have O(1) subscription/unsubscription cost as well. The program from #3469 now produces stunning results:

subscribing...
subscribed so far 10000; took 32ms to subscribe last 10000 at rate: 312500 per sec...
subscribed so far 20000; took 12ms to subscribe last 10000 at rate: 833333 per sec...
subscribed so far 30000; took 14ms to subscribe last 10000 at rate: 714285 per sec...
subscribed so far 40000; took 6ms to subscribe last 10000 at rate: 1666666 per sec...
subscribed so far 50000; took 12ms to subscribe last 10000 at rate: 833333 per sec...
subscribed so far 60000; took 4ms to subscribe last 10000 at rate: 2500000 per sec...
subscribed so far 70000; took 5ms to subscribe last 10000 at rate: 2000000 per sec...
subscribed so far 80000; took 5ms to subscribe last 10000 at rate: 2000000 per sec...
subscribed so far 90000; took 4ms to subscribe last 10000 at rate: 2500000 per sec...
subscribed so far 100000; took 13ms to subscribe last 10000 at rate: 769230 per sec...
subscribed so far 110000; took 4ms to subscribe last 10000 at rate: 2500000 per sec...
subscribed so far 120000; took 5ms to subscribe last 10000 at rate: 2000000 per sec...
subscribed so far 130000; took 5ms to subscribe last 10000 at rate: 2000000 per sec...
subscribed so far 140000; took 4ms to subscribe last 10000 at rate: 2500000 per sec...
subscribed so far 150000; took 5ms to subscribe last 10000 at rate: 2000000 per sec...
subscribed so far 160000; took 6ms to subscribe last 10000 at rate: 1666666 per sec...
subscribed so far 170000; took 41ms to subscribe last 10000 at rate: 243902 per sec...
subscribed so far 180000; took 5ms to subscribe last 10000 at rate: 2000000 per sec...
subscribed so far 190000; took 5ms to subscribe last 10000 at rate: 2000000 per sec...
subscribed so far 200000; took 19ms to subscribe last 10000 at rate: 526315 per sec...
subscribed so far 210000; took 4ms to subscribe last 10000 at rate: 2500000 per sec...
subscribed so far 220000; took 3ms to subscribe last 10000 at rate: 3333333 per sec...
subscribed so far 230000; took 4ms to subscribe last 10000 at rate: 2500000 per sec...
subscribed so far 240000; took 4ms to subscribe last 10000 at rate: 2500000 per sec...
subscribed so far 250000; took 4ms to subscribe last 10000 at rate: 2500000 per sec...
subscribed so far 260000; took 4ms to subscribe last 10000 at rate: 2500000 per sec...
subscribed so far 270000; took 4ms to subscribe last 10000 at rate: 2500000 per sec...
subscribed so far 280000; took 4ms to subscribe last 10000 at rate: 2500000 per sec...
subscribed so far 290000; took 4ms to subscribe last 10000 at rate: 2500000 per sec...
subscribed so far 300000; took 4ms to subscribe last 10000 at rate: 2500000 per sec...
unsubscribing...
unsubscribed so far 10000; took 13ms to unsubscribe last 10000 at rate: 769230 per sec...
unsubscribed so far 20000; took 8ms to unsubscribe last 10000 at rate: 1250000 per sec...
unsubscribed so far 30000; took 7ms to unsubscribe last 10000 at rate: 1428571 per sec...
unsubscribed so far 40000; took 5ms to unsubscribe last 10000 at rate: 2000000 per sec...
unsubscribed so far 50000; took 5ms to unsubscribe last 10000 at rate: 2000000 per sec...
unsubscribed so far 60000; took 5ms to unsubscribe last 10000 at rate: 2000000 per sec...
unsubscribed so far 70000; took 3ms to unsubscribe last 10000 at rate: 3333333 per sec...
unsubscribed so far 80000; took 3ms to unsubscribe last 10000 at rate: 3333333 per sec...
unsubscribed so far 90000; took 3ms to unsubscribe last 10000 at rate: 3333333 per sec...
unsubscribed so far 100000; took 3ms to unsubscribe last 10000 at rate: 3333333 per sec...
unsubscribed so far 110000; took 3ms to unsubscribe last 10000 at rate: 3333333 per sec...
unsubscribed so far 120000; took 3ms to unsubscribe last 10000 at rate: 3333333 per sec...
unsubscribed so far 130000; took 3ms to unsubscribe last 10000 at rate: 3333333 per sec...
unsubscribed so far 140000; took 2ms to unsubscribe last 10000 at rate: 5000000 per sec...
unsubscribed so far 150000; took 3ms to unsubscribe last 10000 at rate: 3333333 per sec...
unsubscribed so far 160000; took 2ms to unsubscribe last 10000 at rate: 5000000 per sec...
unsubscribed so far 170000; took 3ms to unsubscribe last 10000 at rate: 3333333 per sec...
unsubscribed so far 180000; took 2ms to unsubscribe last 10000 at rate: 5000000 per sec...
unsubscribed so far 190000; took 3ms to unsubscribe last 10000 at rate: 3333333 per sec...
unsubscribed so far 200000; took 2ms to unsubscribe last 10000 at rate: 5000000 per sec...
unsubscribed so far 210000; took 2ms to unsubscribe last 10000 at rate: 5000000 per sec...
unsubscribed so far 220000; took 2ms to unsubscribe last 10000 at rate: 5000000 per sec...
unsubscribed so far 230000; took 2ms to unsubscribe last 10000 at rate: 5000000 per sec...
unsubscribed so far 240000; took 2ms to unsubscribe last 10000 at rate: 5000000 per sec...
unsubscribed so far 250000; took 2ms to unsubscribe last 10000 at rate: 5000000 per sec...
unsubscribed so far 260000; took 2ms to unsubscribe last 10000 at rate: 5000000 per sec...
unsubscribed so far 270000; took 2ms to unsubscribe last 10000 at rate: 5000000 per sec...
unsubscribed so far 280000; took 2ms to unsubscribe last 10000 at rate: 5000000 per sec...
unsubscribed so far 290000; took 2ms to unsubscribe last 10000 at rate: 5000000 per sec...
unsubscribed so far 300000; took 3ms to unsubscribe last 10000 at rate: 3333333 per sec...

(The numbers could be actually higher but Windows' timer resolution is about 3ms at best).

@akarnokd akarnokd force-pushed the ReplayRequestCoordinationPerfFix branch from 0d6cf2d to 910000c Compare October 27, 2015 16:55
@akarnokd
Copy link
Member Author

I've updated the code to avoid the synchronized block on each replay attempt in case the cached version of the InnerProducers is still the same as the set's version.

@davidmoten
Copy link
Collaborator

I haven't reviewed the changes in detail yet but I do notice that OpenHashSet doesn't have any dedicated unit tests.

@akarnokd akarnokd force-pushed the ReplayRequestCoordinationPerfFix branch from 910000c to 464568d Compare October 28, 2015 07:50
@akarnokd
Copy link
Member Author

I've added a unit test for OpenHashSet.

@akarnokd akarnokd force-pushed the ReplayRequestCoordinationPerfFix branch from 464568d to 53a74e4 Compare October 28, 2015 18:02
@akarnokd
Copy link
Member Author

Strangely, the test doesn't crash with Java 8. Must be some difference between what type for-each extracts.

@artem-zinnatullin
Copy link
Contributor

@akarnokd needs rebase on latest 1.x

@akarnokd
Copy link
Member Author

akarnokd commented Apr 4, 2016

Thanks. Working on it.

@akarnokd akarnokd force-pushed the ReplayRequestCoordinationPerfFix branch from 713fbe1 to b361d7a Compare April 4, 2016 19:21
@akarnokd
Copy link
Member Author

akarnokd commented Apr 4, 2016

Rebased.

@ZacSweers
Copy link
Contributor

I like this a lot, and the results are really impressive. Code looks good to me, cleaner than the previous implementation too. 👍

@stevegury
Copy link
Member

I finally find some time to review this one, sorry for the delay.
👍

@akarnokd akarnokd merged commit 67b7be0 into ReactiveX:1.x Jun 15, 2016
@akarnokd akarnokd deleted the ReplayRequestCoordinationPerfFix branch June 15, 2016 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants