Commit ce4e02d
committed
Cut send-message latency 50-170x: hostname cache + fetchMembers backoff
Symptom: pilotctl send-message took 10-30 seconds per call against a
warm tunnel — actual relay RTT is ~170ms. Per-step tracing showed:
TRACE parseAddrOrHostname 6879ms ← shared regConn mutex contention
TRACE dataexchange.Dial ~200ms
TRACE client.Recv ~200ms
The PolicyRunner's reconcileMembership ticker fires every 5s and calls
ListNodes on the regConn. For a network with thousands of members
(network 9 = ~10k+ peers in this fleet), the response exceeds the
client read window and EOFs mid-stream. The reconnect cycle pounds the
regConn lock continuously, so any other call (resolve_hostname,
lookup, etc.) that needs regConn blocks until the next failure cycle
completes.
Two complementary fixes:
1. Daemon-side hostname cache (pkg/daemon/ipc.go handleResolveHostname):
60s positive cache keyed on the literal hostname string. Repeated
send-message calls to the same agent serve from cache without
touching regConn at all. Negative results are NOT cached — transient
registry errors don't poison lookups.
2. Exponential backoff on fetchMembers (pkg/daemon/policy_runner.go):
On EOF/error, skip the next ticks for 5s → 10s → 20s → 40s → 80s,
capped at 5 minutes. Reset to 5s on first success. Logs only on
power-of-two failure transitions to avoid spam. Stops the regConn
lock from being held continuously by a doomed call.
Bonus: pilotctl send-message gains an opt-in PILOTCTL_TRACE_TIME=1 env
flag for latency debugging — prints per-step timings to stderr.
Measured: 6879ms hostname → 0.2ms cached. Cold call 1.6s → warm call
175ms. Total send-message reduced from 10-30s to ~600ms cold / ~170ms
warm.1 parent 26824f4 commit ce4e02d
4 files changed
Lines changed: 118 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2848 | 2848 | | |
2849 | 2849 | | |
2850 | 2850 | | |
| 2851 | + | |
| 2852 | + | |
| 2853 | + | |
| 2854 | + | |
| 2855 | + | |
| 2856 | + | |
| 2857 | + | |
| 2858 | + | |
| 2859 | + | |
| 2860 | + | |
| 2861 | + | |
2851 | 2862 | | |
| 2863 | + | |
2852 | 2864 | | |
2853 | 2865 | | |
2854 | 2866 | | |
| 2867 | + | |
2855 | 2868 | | |
2856 | 2869 | | |
2857 | 2870 | | |
| |||
2863 | 2876 | | |
2864 | 2877 | | |
2865 | 2878 | | |
| 2879 | + | |
2866 | 2880 | | |
2867 | 2881 | | |
2868 | 2882 | | |
| |||
2883 | 2897 | | |
2884 | 2898 | | |
2885 | 2899 | | |
| 2900 | + | |
2886 | 2901 | | |
2887 | 2902 | | |
2888 | 2903 | | |
2889 | 2904 | | |
2890 | 2905 | | |
2891 | 2906 | | |
| 2907 | + | |
2892 | 2908 | | |
2893 | 2909 | | |
2894 | 2910 | | |
| |||
2902 | 2918 | | |
2903 | 2919 | | |
2904 | 2920 | | |
| 2921 | + | |
2905 | 2922 | | |
2906 | 2923 | | |
2907 | 2924 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
201 | 213 | | |
202 | 214 | | |
203 | 215 | | |
| |||
234 | 246 | | |
235 | 247 | | |
236 | 248 | | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
237 | 257 | | |
238 | 258 | | |
239 | 259 | | |
| |||
329 | 349 | | |
330 | 350 | | |
331 | 351 | | |
| 352 | + | |
332 | 353 | | |
333 | 354 | | |
334 | 355 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
820 | 820 | | |
821 | 821 | | |
822 | 822 | | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
823 | 849 | | |
824 | 850 | | |
825 | 851 | | |
826 | 852 | | |
827 | 853 | | |
828 | 854 | | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
829 | 862 | | |
830 | 863 | | |
831 | 864 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
50 | 60 | | |
51 | 61 | | |
52 | 62 | | |
| |||
1035 | 1045 | | |
1036 | 1046 | | |
1037 | 1047 | | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
1038 | 1058 | | |
1039 | 1059 | | |
1040 | | - | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
1041 | 1078 | | |
1042 | 1079 | | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
1043 | 1089 | | |
1044 | 1090 | | |
1045 | 1091 | | |
| |||
0 commit comments