Commit a6eed3a
Venkatesh Duggirala
Bug#20574628: SEMI-SYNC REPLICATION PERFORMANCE DEGRADES WITH A HIGH NUMBER OF THREADS
Problem:
when semi-sync replication is enabled and
when the number of threads running is increasing (going beyond a
threshold), performance of the system is going drastically down.
Analysis:
A transaction in semi-sync replication waits for the ACK
inside ReplSemiSyncMaster::commitTrx on a condition variable
COND_binlog_send_. In reportReplyBinlog function, when server
receives an ACK, it sends condition broadcast to all the
threads that are waiting on COND_binlog_send_.
Each transaction thread waiting an ACK does the follow (simplified):
- hold a lock LOCK_binlog_
- in a loop ( while (is_on()) ) :
- compare the ACK position with its own position;
- if the ACK is still behind, it waits on a condition variable COND_binlog_send_
- if the ACK is ahead or equal, it exits this loop and
proceeds with the next step
- unlock the lock LOCK_binlog_
The problem here with this design is that all the threads wake up and while it
is likely that only few will return to the application and most of them will
go back to wait on the same condition variable. This creates unnecessary context
switches and a lot of LLC cache thrashing in multi-cpu systems
which reduces the throughput of the system.
Fix: The approach splits the *one* condvar used for all threads
to wait into *several* condvars. Each of the condvars is associated
with a position range. Thence only those that fall threads that are waiting
for a given acknowledged range are awaken when the ACK comes back
(as opposed to waking up all transactions, regardless whether the ACK affects
them or not).1 parent e2558f5 commit a6eed3a
2 files changed
Lines changed: 101 additions & 55 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
224 | 223 | | |
225 | 224 | | |
226 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
227 | 274 | | |
228 | 275 | | |
229 | 276 | | |
| |||
238 | 285 | | |
239 | 286 | | |
240 | 287 | | |
241 | | - | |
| 288 | + | |
| 289 | + | |
242 | 290 | | |
243 | 291 | | |
244 | 292 | | |
| |||
365 | 413 | | |
366 | 414 | | |
367 | 415 | | |
368 | | - | |
369 | | - | |
370 | 416 | | |
371 | 417 | | |
372 | 418 | | |
| |||
442 | 488 | | |
443 | 489 | | |
444 | 490 | | |
445 | | - | |
446 | 491 | | |
447 | 492 | | |
448 | 493 | | |
| |||
458 | 503 | | |
459 | 504 | | |
460 | 505 | | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | 506 | | |
478 | 507 | | |
479 | 508 | | |
| |||
579 | 608 | | |
580 | 609 | | |
581 | 610 | | |
582 | | - | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | 611 | | |
587 | 612 | | |
588 | 613 | | |
| |||
612 | 637 | | |
613 | 638 | | |
614 | 639 | | |
615 | | - | |
616 | 640 | | |
617 | 641 | | |
618 | 642 | | |
619 | 643 | | |
620 | 644 | | |
621 | | - | |
622 | | - | |
| 645 | + | |
623 | 646 | | |
624 | | - | |
| 647 | + | |
625 | 648 | | |
626 | 649 | | |
627 | 650 | | |
| |||
648 | 671 | | |
649 | 672 | | |
650 | 673 | | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
651 | 684 | | |
652 | | - | |
| 685 | + | |
653 | 686 | | |
654 | 687 | | |
655 | 688 | | |
| |||
751 | 784 | | |
752 | 785 | | |
753 | 786 | | |
754 | | - | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
755 | 792 | | |
756 | 793 | | |
757 | 794 | | |
| |||
790 | 827 | | |
791 | 828 | | |
792 | 829 | | |
793 | | - | |
794 | | - | |
795 | | - | |
796 | | - | |
797 | | - | |
798 | | - | |
799 | | - | |
800 | | - | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
801 | 836 | | |
802 | 837 | | |
803 | 838 | | |
| |||
838 | 873 | | |
839 | 874 | | |
840 | 875 | | |
841 | | - | |
842 | | - | |
843 | | - | |
844 | | - | |
845 | 876 | | |
846 | 877 | | |
847 | 878 | | |
848 | 879 | | |
849 | | - | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
850 | 887 | | |
851 | 888 | | |
852 | 889 | | |
| |||
1234 | 1271 | | |
1235 | 1272 | | |
1236 | 1273 | | |
| 1274 | + | |
1237 | 1275 | | |
1238 | 1276 | | |
1239 | 1277 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
33 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
128 | 129 | | |
129 | 130 | | |
130 | 131 | | |
| 132 | + | |
131 | 133 | | |
132 | 134 | | |
133 | 135 | | |
| |||
246 | 248 | | |
247 | 249 | | |
248 | 250 | | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
249 | 257 | | |
250 | 258 | | |
251 | 259 | | |
| |||
257 | 265 | | |
258 | 266 | | |
259 | 267 | | |
| 268 | + | |
| 269 | + | |
260 | 270 | | |
261 | 271 | | |
262 | 272 | | |
| |||
330 | 340 | | |
331 | 341 | | |
332 | 342 | | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
333 | 348 | | |
334 | 349 | | |
335 | 350 | | |
| |||
376 | 391 | | |
377 | 392 | | |
378 | 393 | | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | 394 | | |
385 | 395 | | |
386 | 396 | | |
| |||
434 | 444 | | |
435 | 445 | | |
436 | 446 | | |
437 | | - | |
438 | | - | |
439 | 447 | | |
440 | 448 | | |
441 | 449 | | |
| |||
0 commit comments