Skip to content

Remove magicsock heartbeat pings entirely ("silent disco") #540

Open

Description

@bradfitz

Currently, active peers heartbeat with each other every 2 seconds.

(@danderson and I had discussed this and considered several options; the overall constraint is we want to only ever be without a network connection for 5 seconds max, before failing back to DERP, so we need a heartbeat at least half that, ideally.)

Unfortunately, every 2 seconds is in both directions, and each ping also involves a pong.

So every 2 seconds:

srv: 8.9M/0.0M magicsock: disco: d:de3ee729b55e7f2f<-d:c9b9fc10e4b34938 ([MINwg], 167.71.156.251:41641)  got ping tx=0ada6c80d510
srv: 8.9M/0.0M magicsock: disco: d:de3ee729b55e7f2f->d:c9b9fc10e4b34938 ([MINwg], 167.71.156.251:41641) sent pong tx=0ada6c80d510
srv: 8.9M/0.0M magicsock: disco: d:de3ee729b55e7f2f->d:c9b9fc10e4b34938 ([MINwg], 167.71.156.251:41641) sent ping tx=764870a09f60
srv: 8.9M/0.0M magicsock: disco: d:de3ee729b55e7f2f<-d:c9b9fc10e4b34938 ([MINwg], 167.71.156.251:41641)  got pong tx=764870a09f60 latency=23ms pong.src=209.180.207.193:49249

Which works out to 2 packets per second.

I think we can get that down to 1/4 that.

We can have a bit in the Ping frame that says "I'm a heartbeat ping, no need to reply right away." (a ping frame used for health, not latency). Then the response Pong can both say 1) how long it was delay (so the pinger can still compute pretty accurate ping time, less the delay time), and 2), can carry its own Ping challenge for its direction along with the Pong response.

Then we'd be back down to just 1 packet every 2 seconds, with the pings from each direction 1 second out of phase.

Alternatively, we do something like elect the lexicographically lesser disco endpoint as the heartbeat pinger and only ping in one direction. The ponger then just trusts the path if it got pings from it. That optimization would only come into play when the path is symmetric, which I imagine it is almost always (I haven't analyzed logs yet, but it seems to be).

Activity

  1. DentonGentry commented on Feb 8, 2021

    @DentonGentry
    Contributor

    I think this is done in 1.4.

  2. bradfitz commented on Feb 8, 2021

    @bradfitz
    MemberAuthor

    This is a different optimization.

  3. DentonGentry commented on Oct 13, 2021

    @DentonGentry
    Contributor

    Related:
    corp PR 2874 suppressed sending certain map poll updates to mobile clients
    Tailscale 1.16 disabled TCP keepalives

  4. DentonGentry commented on Dec 18, 2021

    @DentonGentry
    Contributor

    There is more to be done about radio management to reduce power consumption, but do we believe that 1.16 did enough about heartbeat ping to consider this part done?

  5. bradfitz commented on Dec 18, 2021

    @bradfitz
    MemberAuthor

    No, this should stay open.

  6. changed the title [-]Reduce heartbeat ping rate[/-] [+]Remove magicsock heartbeat pings entirely[/+] on Apr 25, 2022
  7. self-assigned this
    on Apr 25, 2022
  8. bradfitz commented on Sep 16, 2022

    @bradfitz
    MemberAuthor

    Update: the plan is to remove the heartbeats entirely. Magicsock should never transmit unless it has something to transmit anyway, in which case it can send an extra disco packet(s) at that time (or shortly thereafter).

    After certain time cliffs, confidence of a NAT-traversed path decrease (e.g. after 15 or 30 or 60 seconds: might've hit a UDP NAT mapping timeout) so at that point we can switch doing concurrent DERP + copy of packet directly over UDP (hope for the best) + disco refresh.

  9. 28 remaining items

  10. added a commit that references this issue on Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions