Skip to content

High CPU usage with 1 million routes in table #7621

Open

Description

@davidbalbert

What is the issue?

I've been replacing the previous iteration of the VPN we use for managing our network equipment with Tailscale and ran into a snag.

Last night I put Tailscale on our BGP router. It's a Supermicro 5018D-FN8T with a 4 core, 8 thread Broadwell-based Xeon D-1518 running Ubuntu 22.04 and FRR. We're getting full IPv4+IPv6 tables – 1.07 million routes – from a single upstream provider (our backup is just sending a default route).

Without Tailscale, our CPU usage is basically zero – htop reports a load average of between 0.1 and 0.2 out of 8, or between 1.25 and 2.5% total utilization.

With Tailscale, Load average is between 1.6 and 1.8, and htop reports tailscaled using between 150% and 300% CPU. I took this measurement while SSH'd in via a public IP address, so there was no traffic going over tailscale0.

After running tailscale down and tailscale logout, tailscaled uses less CPU, but it still runs hot – Between 20% and 170% CPU with a load average of ~0.5.

Here's the output of the top command in go tool pprof on the results of tailscale debug --cpu-profile while Tailscale was logged in and running:

(pprof) top 20
Showing nodes accounting for 20.07s, 73.03% of 27.48s total
Dropped 218 nodes (cum <= 0.14s)
Showing top 20 nodes out of 125
      flat  flat%   sum%        cum   cum%
     7.62s 27.73% 27.73%      7.62s 27.73%  runtime/internal/syscall.Syscall6
     1.69s  6.15% 33.88%      7.02s 25.55%  runtime.mallocgc
     1.65s  6.00% 39.88%      1.65s  6.00%  runtime.memclrNoHeapPointers
     1.50s  5.46% 45.34%      5.61s 20.41%  runtime.scanobject
     0.95s  3.46% 48.80%      1.56s  5.68%  runtime.findObject
     0.85s  3.09% 51.89%      1.91s  6.95%  runtime.greyobject
     0.84s  3.06% 54.95%      0.88s  3.20%  runtime.pageIndexOf (inline)
     0.62s  2.26% 57.21%      0.62s  2.26%  runtime.memmove
     0.61s  2.22% 59.43%      0.61s  2.22%  runtime.nextFreeFast (inline)
     0.47s  1.71% 61.14%      0.47s  1.71%  runtime.madvise
     0.46s  1.67% 62.81%      0.52s  1.89%  runtime.writeHeapBits.flush
     0.42s  1.53% 64.34%      1.54s  5.60%  github.com/mdlayher/netlink.(*Attribute).unmarshal
     0.42s  1.53% 65.87%      0.43s  1.56%  runtime.heapBitsForAddr
     0.29s  1.06% 66.92%      8.26s 30.06%  github.com/mdlayher/netlink.(*conn).Receive
     0.29s  1.06% 67.98%      6.12s 22.27%  runtime.gcDrain
     0.29s  1.06% 69.03%      0.38s  1.38%  runtime.spanOf (inline)
     0.28s  1.02% 70.05%      4.10s 14.92%  github.com/jsimonetti/rtnetlink.(*RouteAttributes).decode
     0.28s  1.02% 71.07%      0.28s  1.02%  runtime.writeHeapBits.write
     0.27s  0.98% 72.05%      0.27s  0.98%  runtime.heapBits.nextFast (inline)
     0.27s  0.98% 73.03%      1.13s  4.11%  runtime.heapBitsSetType

Seeing netlink in there increases my confidence that the issue has to do with the size of or the churn in the routing table. I've attached the CPU profile.

For now, I've removed Tailscale from the router. It isn't the end of the world – the router's at the edge of our network, so it's publicly addressable – but the non-uniformity makes our setup a bit harder to maintain and document.

Expected behavior

Tailscale doesn't take much CPU to run, and its CPU utilization is proportional to the amount of traffic going over the tunnel. Having a large routing table with regular churn does not effect Tailscale's CPU usage.

Actual behavior

Having a large routing table with regular churn causes Tailscale to use almost 1/3 of the available CPU on a moderately powerful system.

Let me know if there's any other data that would be helpful.

Steps to reproduce

No response

Are there any recent changes that introduced the issue?

I just put Tailscale on this box, so I'm not sure.

OS

Linux

OS version

Ubuntu 22.04

Tailscale version

1.38.1

Other software

  • FRR - bgpd, bfdd, staticd and zebra.
  • iptables (netfilter backend) + conntrack for local traffic destined to and originating from the router. No filters on forwarded traffic.
  • Two non-Tailscale WireGuard tunnels using the wireguard kernel module.

Bug report

BUG-7a32503ac49e9b8957ba8fe91a4af06754123ea68440265d49a7fc5c636752a5-20230320220414Z-d196d3a42f9b574a

Activity

  1. davidbalbert commented on Mar 20, 2023

    @davidbalbert
    Author

    Should have added: This system wasn't acting as an exit node or subnet router.

  2. changed the title [-]High CPU usage in the face of routing table churn (Tailscale 1.38.1, Ubuntu 22.04)[/-] [+]High CPU usage with 1 million routes in table[/+] on Mar 27, 2023
  3. added
    L1 Very few
    P2 Aggravating
    T5 Usability
    and removed on Mar 27, 2023
  4. lukegb commented on Apr 15, 2023

    @lukegb

    For my purposes here I use a custom build of Tailscale using approximately this Nix derivation:

    tailscale.overrideAttrs (old: {
      postPatch = ''
        ${old.postPatch or ""}
    
        # Always use the polling monitor on routers.  The netlink-based monitor is
        # effectively just a wakeup-every-250ms system which causes ridiculously
        # high CPU.
        rm wgengine/monitor/monitor_linux.go
        substituteInPlace wgengine/monitor/monitor_polling.go \
          --replace \
            "//go:build (!linux && !freebsd && !windows && !darwin) || android" \
            ""
      '';
    })

    This is obviously much less good at noticing network condition changes, but on routers I don't mind so much and trading that off against having Tailscale not output millions of log lines while consuming 1.5 cores all the time is probably for the best.

    If we could have an environment variable tunable to switch to the polling monitor, or possibly some heuristic inside the netlink-based one that notices that it's very expensive/high churn rate (something like "have I been woken up every debounce interval for the last 10 debounce intervals"?), that would probably help significantly.

    There are still some CPU spikes, but nothing as drastic as the current situation.

  5. bradfitz commented on Apr 17, 2023

    @bradfitz
    Member

    @davidbalbert, FWIW I have the same SuperMicros and also run Tailscale (albeit an old version) on a full router with the ~same number of routes. I wonder if this is a regression. I'd already done some work to optimize this in the past. I'll upgrade my Tailscale and look what's happening.

  6. davidbalbert commented on Apr 17, 2023

    @davidbalbert
    Author

    @bradfitz thank you! Curious to see what you find.

  7. bradfitz commented on Apr 17, 2023

    @bradfitz
    Member

    On my router, I ran:

    # tailscale version
    1.39.147
      track: unstable (dev); frequent updates and bugs are likely
      tailscale commit: 9e50da321b96567e688b68b7a1d9510c20642766
      other commit: 0f6029a8b1c4b4261c217cfa1dd01cfdbeec91b7
      go version: go1.20.3-tsddff070
    # tailscale debug -cpu-profile=prof.cpu --profile-seconds=60
    

    Then copied the to my desktop and ran:

    $ go tool pprof prof.cpu
    (pprof) top
    Showing nodes accounting for 1.36s, 89.47% of 1.52s total
    Showing top 10 nodes out of 202
          flat  flat%   sum%        cum   cum%
         1.09s 71.71% 71.71%      1.09s 71.71%  runtime/internal/syscall.Syscall6
         0.11s  7.24% 78.95%      0.11s  7.24%  go4.org/mem.AppendFields
         0.03s  1.97% 80.92%      0.05s  3.29%  runtime.findRunnable
         0.03s  1.97% 82.89%      0.03s  1.97%  runtime.memclrNoHeapPointers
         0.02s  1.32% 84.21%      0.02s  1.32%  runtime.nextFreeFast
         0.02s  1.32% 85.53%      0.02s  1.32%  strconv.ParseUint
         0.02s  1.32% 86.84%      0.02s  1.32%  tailscale.com/envknob.RegisterBool.func1
         0.02s  1.32% 88.16%      0.15s  9.87%  tailscale.com/net/interfaces.likelyHomeRouterIPLinux.func1
         0.01s  0.66% 88.82%      0.01s  0.66%  fmt.(*buffer).writeString
         0.01s  0.66% 89.47%      0.01s  0.66%  indexbytebody
    (pprof) top --cum 40
    Showing nodes accounting for 1110ms, 73.03% of 1520ms total
    Showing top 40 nodes out of 202
          flat  flat%   sum%        cum   cum%
        1090ms 71.71% 71.71%     1090ms 71.71%  runtime/internal/syscall.Syscall6
             0     0% 71.71%     1070ms 70.39%  syscall.RawSyscall6
             0     0% 71.71%      750ms 49.34%  syscall.Syscall
             0     0% 71.71%      710ms 46.71%  internal/poll.(*FD).Read
             0     0% 71.71%      710ms 46.71%  internal/poll.ignoringEINTRIO (inline)
             0     0% 71.71%      710ms 46.71%  os.(*File).Read
             0     0% 71.71%      710ms 46.71%  os.(*File).read (inline)
             0     0% 71.71%      710ms 46.71%  syscall.Read (inline)
             0     0% 71.71%      710ms 46.71%  syscall.read
             0     0% 71.71%      490ms 32.24%  tailscale.com/net/interfaces.LikelyHomeRouterIP
             0     0% 71.71%      490ms 32.24%  tailscale.com/net/interfaces.likelyHomeRouterIPLinux
             0     0% 71.71%      490ms 32.24%  tailscale.com/net/portmapper.(*Client).gatewayAndSelfIP
             0     0% 71.71%      490ms 32.24%  tailscale.com/wgengine/monitor.(*Mon).GatewayAndSelfIP
             0     0% 71.71%      480ms 31.58%  tailscale.com/util/lineread.File
             0     0% 71.71%      460ms 30.26%  tailscale.com/util/lineread.Reader
             0     0% 71.71%      450ms 29.61%  tailscale.com/portlist.(*Poller).Run
             0     0% 71.71%      450ms 29.61%  tailscale.com/portlist.(*Poller).getList
             0     0% 71.71%      450ms 29.61%  tailscale.com/portlist.(*Poller).runWithTickChan
             0     0% 71.71%      450ms 29.61%  tailscale.com/portlist.(*linuxImpl).AppendListeningPorts
             0     0% 71.71%      410ms 26.97%  bufio.(*Reader).ReadSlice
             0     0% 71.71%      410ms 26.97%  bufio.(*Reader).fill
             0     0% 71.71%      410ms 26.97%  tailscale.com/portlist.(*linuxImpl).parseProcNetFile
             0     0% 71.71%      330ms 21.71%  syscall.NetlinkRIB
             0     0% 71.71%      310ms 20.39%  bufio.(*Scanner).Scan
             0     0% 71.71%      310ms 20.39%  tailscale.com/net/portmapper.(*Client).createMapping
             0     0% 71.71%      310ms 20.39%  tailscale.com/net/portmapper.(*Client).createOrGetMapping
             0     0% 71.71%      280ms 18.42%  syscall.Syscall6
             0     0% 71.71%      280ms 18.42%  tailscale.com/net/interfaces.GetState
             0     0% 71.71%      260ms 17.11%  tailscale.com/net/interfaces.ForeachInterface
             0     0% 71.71%      250ms 16.45%  tailscale.com/wgengine/magicsock.(*Conn).determineEndpoints
             0     0% 71.71%      250ms 16.45%  tailscale.com/wgengine/magicsock.(*Conn).updateEndpoints
             0     0% 71.71%      180ms 11.84%  net.(*Interface).Addrs
             0     0% 71.71%      180ms 11.84%  net.interfaceAddrTable
             0     0% 71.71%      180ms 11.84%  tailscale.com/net/interfaces.Interface.Addrs (inline)
             0     0% 71.71%      180ms 11.84%  tailscale.com/net/netcheck.(*reportState).probePortMapServices
             0     0% 71.71%      180ms 11.84%  tailscale.com/net/portmapper.(*Client).Probe
             0     0% 71.71%      170ms 11.18%  net.Interfaces
             0     0% 71.71%      170ms 11.18%  net.interfaceTable
             0     0% 71.71%      170ms 11.18%  tailscale.com/net/interfaces.netInterfaces
          20ms  1.32% 73.03%      150ms  9.87%  tailscale.com/net/interfaces.likelyHomeRouterIPLinux.func1
    (pprof) web
    

    Screenshot 2023-04-17 at 9 11 11 AM

    /cc @andrew-d

  8. bradfitz commented on Apr 17, 2023

    @bradfitz
    Member

    The earlier optimization was 2a67bea but we can do more.

  9. 13 remaining items

  10. gucki commented on Jul 18, 2023

    @gucki

    I'm also running Tailscale (1.44.0) on a full-table bgp router (using bird) and only see around 5% CPU usage. However, Tailscale seems to produce a lot of traffic to the control-plane and the logs get flooded with:

    Jul 18 21:56:43 router2 tailscaled[710]: [RATELIMIT] format("monitor: %s: src=%v, dst=%v, gw=%v, outif=%v, table=%v") (80 dropped)
    Jul 18 21:56:43 router2 tailscaled[710]: monitor: RTM_NEWROUTE: src=, dst=..., gw=..., outif=3, table=254
    Jul 18 21:56:44 router2 tailscaled[710]: monitor: RTM_NEWROUTE: src=, dst=..., gw=..., outif=4, table=254
    Jul 18 21:56:44 router2 tailscaled[710]: [RATELIMIT] format("monitor: %s: src=%v, dst=%v, gw=%v, outif=%v, table=%v")
    

    What's the reason that Tailscale has to send all route changes to the control-plane? What about implementing a configuration option to make this configurable?

  11. kotiktr commented on Sep 13, 2025

    @kotiktr

    BUG-27d07a97c6f3c6cd7b5d1522bed9875b3a05d436c032e288469fa60f1b4cbf80-20250913200340Z-157c023c3ae310a6

    I had high CPU usage problem, after so many tries, found out that it was caused because I activated Services on admin panel. It might be your problem too.

  12. sfllaw commented on Mar 19, 2026

    @sfllaw
    Contributor

    On modern Linux systems (post CentOS/RHEL 6), could we avoid parsing the virtual files in /proc/net over and over again? I suspect that we’re burning CPU formatting and parsing when we could be using netlink sock_diag(7) to do things a lot more efficiently. Note that I haven’t tried this for real yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

L1 Very fewOS-linuxP2 AggravatingT5 Usabilitybug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions