Is our Nagle disabling for critical messages working?
(node_factory)
| 4829 | |
| 4830 | @pytest.mark.slow_test |
| 4831 | def test_no_delay(node_factory): |
| 4832 | """Is our Nagle disabling for critical messages working?""" |
| 4833 | l1, l2 = node_factory.line_graph(2, opts={'dev-keep-nagle': None, |
| 4834 | 'may_reconnect': True}) |
| 4835 | |
| 4836 | scid = only_one(l1.rpc.listpeerchannels()['channels'])['short_channel_id'] |
| 4837 | routestep = { |
| 4838 | 'amount_msat': 100, |
| 4839 | 'id': l2.info['id'], |
| 4840 | 'delay': 5, |
| 4841 | 'channel': scid |
| 4842 | } |
| 4843 | |
| 4844 | def do_round_trips(n): |
| 4845 | start = time.time() |
| 4846 | for _ in range(n): |
| 4847 | phash = random.randbytes(32).hex() |
| 4848 | l1.rpc.sendpay([routestep], phash) |
| 4849 | with pytest.raises(RpcError, match="WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS"): |
| 4850 | l1.rpc.waitsendpay(phash) |
| 4851 | return time.time() - start |
| 4852 | |
| 4853 | # Probe the actual per-RTT Nagle overhead on this platform with a small |
| 4854 | # sample (10 trips), then scale up for the full run. Linux's TCP Nagle |
| 4855 | # timer fires after ~200ms; macOS/loopback may be much shorter. |
| 4856 | PROBE = 10 |
| 4857 | probe_nagle = do_round_trips(PROBE) |
| 4858 | |
| 4859 | # Test with nagle (full run) |
| 4860 | nagle_time = do_round_trips(100) |
| 4861 | |
| 4862 | del l1.daemon.opts['dev-keep-nagle'] |
| 4863 | del l2.daemon.opts['dev-keep-nagle'] |
| 4864 | l1.restart() |
| 4865 | l2.restart() |
| 4866 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 4867 | |
| 4868 | # Probe without nagle |
| 4869 | probe_normal = do_round_trips(PROBE) |
| 4870 | |
| 4871 | # Test without nagle (full run) |
| 4872 | normal_time = do_round_trips(100) |
| 4873 | |
| 4874 | # Estimate the per-RTT Nagle delay from the probe; average delay is half |
| 4875 | # the timer period. Use half again as variance margin (same logic as the |
| 4876 | # original 200ms assumption). If the platform shows no measurable Nagle |
| 4877 | # effect (e.g. macOS loopback with a very short timer) the expected saving |
| 4878 | # rounds down to zero and we only assert directional ordering. |
| 4879 | per_rtt_delay = max(0.0, (probe_nagle - probe_normal) / PROBE) |
| 4880 | expected_saving = 100 * per_rtt_delay / 2 |
| 4881 | |
| 4882 | print(f"Nagle probe: {probe_nagle:.3f}s nagle, {probe_normal:.3f}s normal, " |
| 4883 | f"per-RTT overhead ~{per_rtt_delay * 1000:.1f}ms, " |
| 4884 | f"expected saving {expected_saving:.2f}s") |
| 4885 | |
| 4886 | if expected_saving > 0.5: |
| 4887 | # Platform shows a meaningful Nagle effect: assert the full saving. |
| 4888 | assert normal_time < nagle_time - expected_saving |
nothing calls this directly
no test coverage detected