Skip to content

Conversation

@kp-omer-shamash
Copy link
Collaborator

Description

feat: introduce cpu-arch, dashmap, parking_lot

  • Change mutex usage from std to parking_lot (faster impl)
  • Calculate checksums/ip-addr with cpu-native ASM
  • Move from locked hashmap to dashmap (lockfree)

Motivation and Context

9g5ud6

@kp-omer-shamash kp-omer-shamash force-pushed the omer/performance-quick-gains branch from cece100 to fc3bb15 Compare January 13, 2025 10:05
@kp-omer-shamash kp-omer-shamash force-pushed the omer/performance-quick-gains branch from fc3bb15 to b701a31 Compare January 14, 2025 10:38
@kp-omer-shamash
Copy link
Collaborator Author

@kp-mariappan-ramasamy reworked commits and review comments

Comment on lines +169 to +187
let old_bytes = old.octets();
let new_bytes = new.octets();

// Convert to u16 pairs for checksum calculation
let old_words = [
u16::from_be_bytes([old_bytes[0], old_bytes[1]]),
u16::from_be_bytes([old_bytes[2], old_bytes[3]]),
];
let new_words = [
u16::from_be_bytes([new_bytes[0], new_bytes[1]]),
u16::from_be_bytes([new_bytes[2], new_bytes[3]]),
];

Self(vec![
(old_words[0], new_words[0]),
(old_words[1], new_words[1]),
])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

usually loop-unrolling optimization would've fixed this for us, but since we use vec.push - it might miss it, so I unrolled manually

Comment on lines +201 to +205
if unlikely(true) {
warn!(protocol = ?protocol, "Unknown protocol, skipping checksum update");
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if you are wondering on all the unlikely(true) - it's basically a way to ensure that the WARN gets pushed out of the HOT path, so it's intended

let mut tcp_packet = MutableTcpPacket::new(packet.payload_mut()).unwrap();
let checksum = tcp_packet.get_checksum();
// Only update if checksum is present (not 0)
if checksum != 0 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added checksum != 0 check on all layers to allow OFFLOADING to hardware when possible

@kp-omer-shamash kp-omer-shamash force-pushed the omer/performance-quick-gains branch 3 times, most recently from fe3d4bb to e37adb4 Compare January 14, 2025 13:50
@github-actions
Copy link

github-actions bot commented Jan 14, 2025

Code coverage summary for 5dbdad5:

Filename                                                     Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
lightway-app-utils/src/args/cipher.rs                              4                 4     0.00%           1                 1     0.00%           5                 5     0.00%           0                 0         -
lightway-app-utils/src/args/connection_type.rs                     4                 4     0.00%           1                 1     0.00%           5                 5     0.00%           0                 0         -
lightway-app-utils/src/args/duration.rs                            7                 7     0.00%           5                 5     0.00%          13                13     0.00%           0                 0         -
lightway-app-utils/src/args/ip_map.rs                             11                11     0.00%           3                 3     0.00%          15                15     0.00%           0                 0         -
lightway-app-utils/src/args/logging.rs                            14                14     0.00%           2                 2     0.00%          16                16     0.00%           0                 0         -
lightway-app-utils/src/connection_ticker.rs                       39                 4    89.74%          17                 2    88.24%         156                 5    96.79%           0                 0         -
lightway-app-utils/src/dplpmtud_timer.rs                          63                 7    88.89%          22                 4    81.82%         282                11    96.10%           0                 0         -
lightway-app-utils/src/event_stream.rs                             5                 0   100.00%           3                 0   100.00%          13                 0   100.00%           0                 0         -
lightway-app-utils/src/iouring.rs                                144               144     0.00%          29                29     0.00%         455               455     0.00%           0                 0         -
lightway-app-utils/src/metrics.rs                                  4                 4     0.00%           4                 4     0.00%           8                 8     0.00%           0                 0         -
lightway-app-utils/src/sockopt/ip_mtu_discover.rs                 23                23     0.00%           4                 4     0.00%          93                93     0.00%           0                 0         -
lightway-app-utils/src/sockopt/ip_pktinfo.rs                       4                 4     0.00%           1                 1     0.00%          16                16     0.00%           0                 0         -
lightway-app-utils/src/tun.rs                                     77                77     0.00%          22                22     0.00%          95                95     0.00%           0                 0         -
lightway-app-utils/src/utils.rs                                   13                13     0.00%           1                 1     0.00%          11                11     0.00%           0                 0         -
lightway-client/src/args.rs                                       32                32     0.00%          28                28     0.00%          35                35     0.00%           0                 0         -
lightway-client/src/io/inside/tun.rs                              39                39     0.00%           7                 7     0.00%          48                48     0.00%           0                 0         -
lightway-client/src/io/outside/tcp.rs                             48                48     0.00%          10                10     0.00%          45                45     0.00%           0                 0         -
lightway-client/src/io/outside/udp.rs                             60                60     0.00%          12                12     0.00%          61                61     0.00%           0                 0         -
lightway-client/src/keepalive.rs                                 245                33    86.53%          56                 8    85.71%         372                26    93.01%           0                 0         -
lightway-client/src/lib.rs                                       176               176     0.00%          19                19     0.00%         272               272     0.00%           0                 0         -
lightway-client/src/main.rs                                       48                48     0.00%           7                 7     0.00%         166               166     0.00%           0                 0         -
lightway-core/src/borrowed_bytesmut.rs                            86                 1    98.84%          24                 0   100.00%         196                 1    99.49%           0                 0         -
lightway-core/src/builder_predicates.rs                           20                10    50.00%           4                 2    50.00%          28                14    50.00%           0                 0         -
lightway-core/src/cipher.rs                                        8                 0   100.00%           3                 0   100.00%          13                 0   100.00%           0                 0         -
lightway-core/src/connection.rs                                  486               237    51.23%          48                19    60.42%         669               283    57.70%           0                 0         -
lightway-core/src/connection/builders.rs                          59                21    64.41%          18                 7    61.11%         236                54    77.12%           0                 0         -
lightway-core/src/connection/dplpmtud.rs                         761                90    88.17%          66                 1    98.48%         947                11    98.84%           0                 0         -
lightway-core/src/connection/fragment_map.rs                     132                11    91.67%          27                 0   100.00%         290                 7    97.59%           0                 0         -
lightway-core/src/connection/io_adapter.rs                       137                17    87.59%          36                 5    86.11%         313                23    92.65%           0                 0         -
lightway-core/src/connection/key_update.rs                        23                 7    69.57%           5                 0   100.00%          38                19    50.00%           0                 0         -
lightway-core/src/context.rs                                      89                25    71.91%          24                 7    70.83%         197                40    79.70%           0                 0         -
lightway-core/src/context/ip_pool.rs                               7                 3    57.14%           1                 0   100.00%           6                 0   100.00%           0                 0         -
lightway-core/src/context/server_auth.rs                          14                11    21.43%           4                 3    25.00%          24                20    16.67%           0                 0         -
lightway-core/src/io.rs                                            3                 3     0.00%           3                 3     0.00%          10                10     0.00%           0                 0         -
lightway-core/src/lib.rs                                           9                 6    33.33%           4                 1    75.00%          18                 9    50.00%           0                 0         -
lightway-core/src/metrics.rs                                       9                 9     0.00%           7                 7     0.00%          17                17     0.00%           0                 0         -
lightway-core/src/packet.rs                                       27                 7    74.07%           4                 1    75.00%          30                 6    80.00%           0                 0         -
lightway-core/src/plugin.rs                                       66                 8    87.88%          23                 5    78.26%         160                 9    94.38%           0                 0         -
lightway-core/src/utils.rs                                       108                26    75.93%          24                 2    91.67%         199                19    90.45%           0                 0         -
lightway-core/src/version.rs                                      37                 0   100.00%          19                 0   100.00%          89                 0   100.00%           0                 0         -
lightway-core/src/wire.rs                                        140                19    86.43%          32                 0   100.00%         256                 2    99.22%           0                 0         -
lightway-core/src/wire/auth_failure.rs                             9                 1    88.89%           3                 0   100.00%          19                 0   100.00%           0                 0         -
lightway-core/src/wire/auth_request.rs                           147                12    91.84%          34                 0   100.00%         287                 0   100.00%           0                 0         -
lightway-core/src/wire/auth_success_with_config_ipv4.rs           69                 4    94.20%          13                 0   100.00%         145                 0   100.00%           0                 0         -
lightway-core/src/wire/data.rs                                    20                 1    95.00%           7                 0   100.00%          43                 0   100.00%           0                 0         -
lightway-core/src/wire/data_frag.rs                               41                 1    97.56%          17                 0   100.00%          92                 0   100.00%           0                 0         -
lightway-core/src/wire/ping.rs                                    22                 3    86.36%           7                 0   100.00%          68                 0   100.00%           0                 0         -
lightway-core/src/wire/pong.rs                                    15                 2    86.67%           5                 0   100.00%          34                 0   100.00%           0                 0         -
lightway-core/src/wire/server_config.rs                           20                 2    90.00%           5                 0   100.00%          44                 0   100.00%           0                 0         -
lightway-server/src/args.rs                                       29                29     0.00%          29                29     0.00%          29                29     0.00%           0                 0         -
lightway-server/src/auth.rs                                      104                36    65.38%          19                 5    73.68%         148                28    81.08%           0                 0         -
lightway-server/src/connection.rs                                 51                51     0.00%          23                23     0.00%         109               109     0.00%           0                 0         -
lightway-server/src/connection_manager.rs                         87                87     0.00%          25                25     0.00%         198               198     0.00%           0                 0         -
lightway-server/src/connection_manager/connection_map.rs          87                 9    89.66%          26                 2    92.31%         273                 9    96.70%           0                 0         -
lightway-server/src/io/inside/tun.rs                              25                25     0.00%           8                 8     0.00%          34                34     0.00%           0                 0         -
lightway-server/src/io/outside/tcp.rs                             80                80     0.00%           8                 8     0.00%          99                99     0.00%           0                 0         -
lightway-server/src/io/outside/udp.rs                            142               142     0.00%          18                18     0.00%         262               262     0.00%           0                 0         -
lightway-server/src/io/outside/udp/cmsg.rs                        47                16    65.96%          14                 5    64.29%         237                56    76.37%           0                 0         -
lightway-server/src/ip_manager.rs                                 82                25    69.51%          19                 4    78.95%         254                28    88.98%           0                 0         -
lightway-server/src/ip_manager/ip_pool.rs                        101                 1    99.01%          32                 0   100.00%         305                 0   100.00%           0                 0         -
lightway-server/src/lib.rs                                        93                93     0.00%          10                10     0.00%         148               148     0.00%           0                 0         -
lightway-server/src/main.rs                                       65                65     0.00%           9                 9     0.00%         175               175     0.00%           0                 0         -
lightway-server/src/metrics.rs                                    91                89     2.20%          80                78     2.50%         216               212     1.85%           0                 0         -
lightway-server/src/statistics.rs                                 53                23    56.60%           8                 4    50.00%         103                42    59.22%           0                 0         -
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                           4761              2060    56.73%        1049               461    56.05%        9240              3374    63.48%           0                 0         -

✅ Region coverage 56% passes
✅ Line coverage 63% passes

@kp-omer-shamash kp-omer-shamash force-pushed the omer/performance-quick-gains branch 2 times, most recently from ac802b3 to d04f77e Compare January 26, 2025 23:06
@kp-omer-shamash kp-omer-shamash force-pushed the omer/performance-quick-gains branch 2 times, most recently from b655365 to ebfb4bd Compare January 30, 2025 10:14
@kp-omer-shamash kp-omer-shamash marked this pull request as ready for review January 30, 2025 10:14
@kp-omer-shamash kp-omer-shamash requested a review from a team as a code owner January 30, 2025 10:14
@kp-omer-shamash kp-omer-shamash force-pushed the omer/performance-quick-gains branch from c024622 to 2fb5424 Compare February 2, 2025 08:29
@kp-omer-shamash kp-omer-shamash force-pushed the omer/performance-quick-gains branch 11 times, most recently from ae3799e to 66b7f3a Compare February 11, 2025 13:38
@kp-omer-shamash kp-omer-shamash force-pushed the omer/performance-quick-gains branch from 66b7f3a to 4e6c30e Compare February 23, 2025 12:29
this way it'll be kept in commit-history for reference
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.

4 participants