Bug Description: The connection table previously to find an available
slot would iterate over the table attempting to find a free connection.
Under high congestion this yields poor performance as we may need to walk
O(n) slots to find the "one free", and the algorithm allowed the table to
be walked twice, making it potentially a O(2n) worst case. To make this
worse, the walking attempted to "trylock" - better than before (which
really locked!), but the trylock still issues atomics that are costly.
Fix Description: Implement a freelist - at start up all connections are
free, and as they are allocated they are removed from the list. As they
are disconnected they are re-added. This makes the lookup of a connection
O(1), removes spurious atomic and locking behaviour, and helps to minimise
time under the conntable lock. In some test cases this is shown to
improve server throughput by at minimum 6%
Tests were performed between two machines. The target which was running ns-slapd is a 4 core virtual machine with 4GB of ram on 40GB of nvme. The source of load is a 2 core virtual machine with 2 GB of ram on nvme. They are connected via a single virtual switch capable of 10GBit of throughput with no routers between. The server has threadnumber 4 to match cores, and a conntable size of 8192. Both machines are adjusted to support a ulimit of 999999 open file descriptors.
/opt/dirsrv/bin/ldclt -h lt2.dev.blackhats.net.au -p 389 -n 128 -N 10 -f '(uid=user_XXXXXXX)' -e bindeach -e esearch,random -r1 -R6000 -I 32 -e randomattrlist=cn:uid:ou
Original
ldclt[19500]: Average rate: 579.18/thr (7413.50/sec), total: 74135
ldclt[19500]: Average rate: 548.67/thr (7023.00/sec), total: 70230
ldclt[19500]: Average rate: 573.40/thr (7339.50/sec), total: 73395
ldclt[19500]: Average rate: 578.99/thr (7411.10/sec), total: 74111
ldclt[19500]: Average rate: 576.16/thr (7374.80/sec), total: 73748
ldclt[19500]: Average rate: 541.27/thr (6928.30/sec), total: 69283
ldclt[19500]: Average rate: 601.46/thr (7698.70/sec), total: 76987
ldclt[19500]: Average rate: 602.59/thr (7713.10/sec), total: 77131
ldclt[19500]: Average rate: 566.91/thr (7256.50/sec), total: 72565
ldclt[19500]: Average rate: 599.62/thr (7675.10/sec), total: 76751
ldclt[19500]: Number of samples achieved. Bye-bye...
ldclt[19500]: All threads are dead - exit.
ldclt[19500]: Global average rate: 5768.25/thr (7383.36/sec), total: 738336
Freelist
ldclt[19653]: Average rate: 617.07/thr (7898.50/sec), total: 78985
ldclt[19653]: Average rate: 609.56/thr (7802.40/sec), total: 78024
ldclt[19653]: Average rate: 653.90/thr (8369.90/sec), total: 83699
ldclt[19653]: Average rate: 547.12/thr (7003.20/sec), total: 70032
ldclt[19653]: Average rate: 648.23/thr (8297.30/sec), total: 82973
ldclt[19653]: Average rate: 602.27/thr (7709.10/sec), total: 77091
ldclt[19653]: Average rate: 636.16/thr (8142.90/sec), total: 81429
ldclt[19653]: Average rate: 639.76/thr (8188.90/sec), total: 81889
ldclt[19653]: Average rate: 623.45/thr (7980.20/sec), total: 79802
ldclt[19653]: Average rate: 546.29/thr (6992.50/sec), total: 69925
ldclt[19653]: Number of samples achieved. Bye-bye...
ldclt[19653]: All threads are dead - exit.
ldclt[19653]: Global average rate: 6123.82/thr (7838.49/sec), total: 783849
This shows a 6% improvement in the connection throughput.
I may perform some more testing before we merge this.
Bug Description: The connection table previously to find an available
slot would iterate over the table attempting to find a free connection.
Under high congestion this yields poor performance as we may need to walk
O(n) slots to find the "one free", and the algorithm allowed the table to
be walked twice, making it potentially a O(2n) worst case. To make this
worse, the walking attempted to "trylock" - better than before (which
really locked!), but the trylock still issues atomics that are costly.
Fix Description: Implement a freelist - at start up all connections are
free, and as they are allocated they are removed from the list. As they
are disconnected they are re-added. This makes the lookup of a connection
O(1), removes spurious atomic and locking behaviour, and helps to minimise
time under the conntable lock. In some test cases this is shown to
improve server throughput by at minimum 6%
https://pagure.io/389-ds-base/issue/50786
Author: William Brown william@blackhats.net.au
Review by: ???
--
Tests were performed between two machines. The target which was running ns-slapd is a 4 core virtual machine with 4GB of ram on 40GB of nvme. The source of load is a 2 core virtual machine with 2 GB of ram on nvme. They are connected via a single virtual switch capable of 10GBit of throughput with no routers between. The server has threadnumber 4 to match cores, and a conntable size of 8192. Both machines are adjusted to support a ulimit of 999999 open file descriptors.
This shows a 6% improvement in the connection throughput.
I may perform some more testing before we merge this.