envoyproxy / envoy

Cloud-native high-performance edge/middle/service proxy
https://www.envoyproxy.io
Apache License 2.0
24.76k stars 4.76k forks source link

inotify watcher performance issues #3308

Open bplotnick opened 6 years ago

bplotnick commented 6 years ago

Title: inotify watcher is O(N) of watches for each file change

Description: When using the filesystem watcher for EDS configuration, I noticed significant performance overhead for configuration changes. With a large number of clusters (i've tested with ~1000) updating somewhat frequently (I've tested updating them all every 10s), Envoy ends up spending a significant portion of its time simply responding to inotify events. I think i've narrowed it town to a few factors at play.

I've managed to work around this by having each EDS configuration in its own directory, not writing temp files in those directories, and minimizing accesses and other file operations on these files.

I have not tried this using the kqueue watcher.

Repro steps: Create a large number of clusters with an eds_config file for each:

# clusters.yaml jinja template
resources:
{%- for service in services %}
- "@type": "type.googleapis.com/envoy.api.v2.Cluster"
  name: {{ service }}.cluster
  type: EDS
  eds_cluster_config:
    eds_config:
      path: /tmp/xds/endpoints/{{ service }}.yaml
{%- endfor %}

You then just need a basic endpoint file for each cluster (you don't even need endpoints)

# {{ service }}.yaml
resources:
- "@type": type.googleapis.com/envoy.api.v2.ClusterLoadAssignment
  cluster_name: {{ service }}
  endpoints:
  - lb_endpoints:

I was recreating all of these files every 10 seconds or so. Clearly this is the wrong thing to do, but for the first version, it was sufficient.

I've uploaded a pprof callgraph from the cpuprofiler output here. It's in svg format, so you'll need to open the image (e.g. on Chrome, right click and hit "show image in new tab")

jparise commented 5 years ago

6215 reduces the set of watched inotify events from IN_ALL_EVENTS to just those events that are needed.