logstash-codec-netflow icon indicating copy to clipboard operation
logstash-codec-netflow copied to clipboard

Processing performance issue

Open jasonkeller opened this issue 9 years ago • 47 comments

I have an issue where logstash is unable to process more than 3000 events/s of Netflow traffic (around 6.5 Mbit/s); it's currently dropping at least 200 UDP datagrams every second. CPU usage is anywhere from 86-92% across all cores.

More detail on this thread... https://discuss.elastic.co/t/netflow-high-cpu-utilization-and-poor-throughput/94854

  • Version: logstash-codec-netflow-3.4.1
  • Operating System: RHEL7 (VMware, 8 vCPU, 2GB RAM)
  • Config File (if you have sensitive info, please remove it):
cat /etc/logstash/conf.d/netflow.conf
input {
  udp {
    host => "0.0.0.0"
    port => 2055
    codec => netflow { versions => [9] netflow_definitions => "/etc/logstash/netflow.yaml" }
    type => "netflow"
    workers => 8
    queue_size => 8000
  }
}

filter {

translate {
        field => "[netflow][protocol]"
        destination => "[netflow][protocolname]"
        dictionary => [
                        "0","HOPOPT",
                        "1","ICMP",
                        "2","IGMP",
                        "3","GGP",
                        "4","IP-in-IP",
                        "5","ST",
                        "6","TCP",
                        "7","CBT",
                        "8","EGP",
                        "9","IGP",
                        "10","BBN-RCC-MON",
                        "11","NVP-II",
                        "12","PUP",
                        "13","ARGUS",
                        "14","EMCON",
                        "15","XNET",
                        "16","CHAOS",
                        "17","UDP",
                        "18","MUX",
                        "19","DCN-MEAS",
                        "20","HMP",
                        "21","PRM",
                        "22","XNS-IDP",
                        "23","TRUNK-1",
                        "24","TRUNK-2",
                        "25","LEAF-1",
                        "26","LEAF-2",
                        "27","RDP",
                        "28","IRTP",
                        "29","ISO-TP4",
                        "30","NETBLT",
                        "31","MFE-NSP",
                        "32","MERIT-INP",
                        "33","DCCP",
                        "34","3PC",
                        "35","IDPR",
                        "36","XTP",
                        "37","DDP",
                        "38","IDPR-CMTP",
                        "39","TP++",
                        "40","IL",
                        "41","IPv6",
                        "42","SDRP",
                        "43","IPv6-Route",
                        "44","IPv6-Frag",
                        "45","IDRP",
                        "46","RSVP",
                        "47","GRE",
                        "48","DSR",
                        "49","BNA",
                        "50","ESP",
                        "51","AH",
                        "52","I-NLSP",
                        "53","SWIPE",
                        "54","NARP",
                        "55","MOBILE",
                        "56","TLSP",
                        "57","SKIP",
                        "58","IPv6-ICMP",
                        "59","IPv6-NoNxt",
                        "60","IPv6-Opts",
                        "62","CFTP",
                        "64","SAT-EXPAK",
                        "65","KRYPTOLAN",
                        "66","RVD",
                        "67","IPPC",
                        "69","SAT-MON",
                        "70","VISA",
                        "71","IPCU",
                        "72","CPNX",
                        "73","CPHB",
                        "74","WSN",
                        "75","PVP",
                        "76","BR-SAT-MON",
                        "77","SUN-ND",
                        "78","WB-MON",
                        "79","WB-EXPAK",
                        "80","ISO-IP",
                        "81","VMTP",
                        "82","SECURE-VMTP",
                        "83","VINES",
                        "84","TTP",
                        "85","IPTM",
                        "86","NSFNET-IGP",
                        "87","DGP",
                        "88","TCF",
                        "89","EIGRP",
                        "90","OSPF",
                        "91","Sprite-RPC",
                        "92","LARP",
                        "93","MTP",
                        "94","AX.25",
                        "95","OS",
                        "96","MICP",
                        "97","SCC-SP",
                        "98","ETHERIP",
                        "99","ENCAP",
                        "101","GMTP",
                        "102","IFMP",
                        "103","PNNI",
                        "104","PIM",
                        "105","ARIS",
                        "106","SCPS",
                        "107","QNX",
                        "108","A/N",
                        "109","IPComp",
                        "110","SNP",
                        "111","Compaq-Peer",
                        "112","IPX-in-IP",
                        "113","VRRP",
                        "114","PGM",
                        "116","L2TP",
                        "117","DDX",
                        "118","IATP",
                        "119","STP",
                        "120","SRP",
                        "121","UTI",
                        "122","SMP",
                        "123","SM",
                        "124","PTP",
                        "125","IS-IS over IPv4",
                        "126","FIRE",
                        "127","CRTP",
                        "128","CRUDP",
                        "129","SSCOPMCE",
                        "130","IPLT",
                        "131","SPS",
                        "132","PIPE",
                        "133","SCTP",
                        "134","FC",
                        "135","RSVP-E2E-IGNORE",
                        "136","Mobility Header",
                        "137","UDPLite",
                        "138","MPLS-in-IP",
                        "139","manet",
                        "140","HIP",
                        "141","Shim6",
                        "142","WESP",
                        "143","ROHC"
                ]
        }
}
  • Steps to Reproduce: Aim a Palo Alto firewall netflow stream at the server. Current traffic through the firewall is less than half a gigabit on average. I have no errors in my logs from logstash.

jasonkeller avatar Aug 01 '17 18:08 jasonkeller

By 3000 events/sec you mean 3000 UDP packets per sec? Assuming 20 flows per packet, this means 60000 flows per second from you PA.

I haven't been able to benchmark beyond a 2 core laptop setup myself, but adding your Xeon E5 v4 the scaling looks pretty good to me:

CPU vCPU's flows/sec
i7 1 1840
i7 2 3040
E5-2698 8 60000

This looks like you should try extending your VM to >8 cores on the E5, and see what this brings. If you're losing "only" 200 pts/sec compared to the 3000 you should be able to successfully decode your torrential netflow deluge in its entirety with around 10 cores.

jorritfolmer avatar Aug 01 '17 20:08 jorritfolmer

Currently I see around 163965672 records in a 24hr Elasticsearch index (which gives me roughly 1898 per second, sorry my last estimate was off). Which shocked me why I'm seeing such low processing rates (by your numbers it's like I have a single vCPU!). From the numbers I'm seeing in netstat -suna 1 I'm dropping roughly 198 UDP packets/s, assuming 20/packet means potentially 3/5 of my flows on the floor.

Also here's the other shoe - this is only off of a single firewall that I'm getting all these flows from (and it will see much more traffic soon, as will the others). I have at minimum four more firewalls to add, so I'm doomed to create several VMs behind a load balancer to ingest it all, but as long as I can get the quoted flows/s you have above I think we'll be fine.

What other output could I provide you for further diagnosing this issue?

jasonkeller avatar Aug 01 '17 20:08 jasonkeller

To mitigate dropped UDP packets, it seems that the max socket receive buffer is the single most important parameter to increase:

sysctl -w net.core.rmem_max=$((1024*1024*16))

And having the UDP socket allocate that too:

input {
  udp {
    port                 => 2055
    receive_buffer_bytes => 16777216
    codec                => netflow
    workers              => 6
  }
}

Packets will still be lost if the rate at which new packets fill this buffer exceeds the rate at which it can be emptied.

The rate at which the socket buffer can be emptied seems to reach a max at around 6300 flows/sec, with 6 workers. Adding more workers (and vCPU's) doesn't increase the rate. This is the scaling chart from testing on an Amazon c3.4xlarge box (16 vCPU @2.8GHz, E5-2680):

udp workers total pkts total flows time(sec) flows/sec loss %
1 10000 210000 129 1600 0%
2 10000 210000 69 3000 0%
4 10000 210000 42 5000 0%
6 10000 210000 33 6300 0%
8 10000 210000 33 6300 0%
16 10000 210000 33 6300 0%

(I've been testing this with a python script that bursts 10000 UDP Netflow v9 packets totaling 210000 flows, and waiting for Logstash to stop writing to a json_lines output file. Last modtime of file minus start of burst = time taken)

jorritfolmer avatar Aug 02 '17 10:08 jorritfolmer

Thanks @jorritfolmer ; this helped delay the packet loss for a couple minutes, but definitely my processing rate is falling far behind as netstat -neopa | grep udp confirms.

netstat -neopa | grep udp
udp   33551744      0 0.0.0.0:2055            0.0.0.0:*                           995        2120994    60715/java           off (0.00/0/0)
udp        0      0 0.0.0.0:161             0.0.0.0:*                           0          22536      1086/snmpd           off (0.00/0/0)
udp        0      0 127.0.0.1:323           0.0.0.0:*                           0          12079      744/chronyd          off (0.00/0/0)

Instead of adding vCPU, I'm actually going to go the other way and cut it in half, as I suspect our vCPU > pCPU ratio is heavily oversubscribed (which may also help explain the wall you just hit in scaling in AWS as well). The way scheduling works in the hypervisor, this causes you to actually lose CPU time the more vCPU you add to the VM. I will try to test this theory ASAP here. Also, if there are scripts you could share for generating netflow etc, I can actually take and do more testing on a clean, empty host.

jasonkeller avatar Aug 02 '17 12:08 jasonkeller

So I've adjusted the vCPU downward in my current RHEL7 environment, however the queue still stacks up quickly and overwhelms it. I'm actually now losing approximately 400+ UDP packets per second, all of them queue drops.

top -h
  1707 logstash  39  19 5294132 1.105g  15888 R 81.4 62.1   8:46.05 <udp.1
  1708 logstash  39  19 5294132 1.105g  15888 R 81.4 62.1   8:46.63 <udp.2
  1706 logstash  39  19 5294132 1.105g  15888 R 81.1 62.1   8:46.05 <udp.0
  1709 logstash  39  19 5294132 1.105g  15888 R 81.1 62.1   8:45.75 <udp.3
  1669 logstash  39  19 5294132 1.105g  15888 S  9.0 62.1   0:57.75 java
  1672 logstash  39  19 5294132 1.105g  15888 S  9.0 62.1   0:58.40 java
  1670 logstash  39  19 5294132 1.105g  15888 S  8.6 62.1   0:58.13 java
  1671 logstash  39  19 5294132 1.105g  15888 S  8.6 62.1   0:58.09 java
  1702 logstash  39  19 5294132 1.105g  15888 S  2.7 62.1   0:12.73 [main]>worker3
  1700 logstash  39  19 5294132 1.105g  15888 S  2.3 62.1   0:12.77 [main]>worker1
  1699 logstash  39  19 5294132 1.105g  15888 R  2.0 62.1   0:12.70 [main]>worker0
  1674 logstash  39  19 5294132 1.105g  15888 S  1.3 62.1   0:08.42 java
  1701 logstash  39  19 5294132 1.105g  15888 R  1.3 62.1   0:12.79 [main]>worker2
  1679 logstash  39  19 5294132 1.105g  15888 S  1.0 62.1   0:20.28 java
  1680 logstash  39  19 5294132 1.105g  15888 S  1.0 62.1   0:19.58 java
  1703 logstash  39  19 5294132 1.105g  15888 S  0.7 62.1   0:04.14 [main]<udp

From a PCAP it appears that there are a grand total of 8 V9 flow records per UDP packet, with a template hitting every 20-22 packets.

jasonkeller avatar Aug 02 '17 13:08 jasonkeller

Here's my script:

cat << EOF |base64 -d |gunzip -dc > netflow_bench.py
H4sICBvfgVkAA25ldGZsb3dfYmVuY2gucHkAtVhtb9s2EP6uX8Gmy2JnhkHJb1KCADW2JAuKud3W
re0gINELlbhzbNfWNncD9tt3x3dyVorYaRBaPJE88uFzvDtxer9crGqyXhS/szqYSunTWlXr6T0L
guA5mbC6mi3+In8mpGb3y1lWs6BezsgZOUo3lKY1/93QkKWbpEg3Bb1+d5FuYvYLvvwDXoyg0pO9
sMTQGloyLbEnlL54EY5kQySffTWFJ8eeXDjy3GtlrhwOPHno9fdXkbtySL3x3upCd/V6m/hz1YBI
yUNPHtjymS28twW1JDk1y1z1TEHoH3nMllmddUgUEnyxPglQ9hkOB5LhvPgoGH6jGIblZjajimFF
6iBNbb4tYLy0JFcwURIp3sLqR7vP3FWQML6YS1Ruaumm7EnlUPLcm9QqFbRVxkbYM0Fo2Bebr8kN
X6jKja3gplmzthde7jSc8FhUn1t08/J2K7Ir2MJYIxvhdkPp74ZsIBHticwhra+RDReiegALLF3w
2zmbq+cY7IbtBim2IKl17QkJV9HTqEanovoVrDGzR/3aaImFqWEb7HpVdj4DKzSw0OahJFB6Fqon
QAbqikSSdKkRgjFVUeqBseUPEs9KPS2qwCLL0sNiYwMkmTnLOI00Qu53h4JB0fuJjhj8xgM9I6vs
Pk3eQyADZ5YDxXHCtwl6vH6cLdIvd7wOQWWpZ3O2DUvlqsgiZYEhNTWJCOkqdBw+5YodvpJRau0T
moZzyijZjSwbVlSJKUBVbjYx//iQFXYbMElLRFiVNWCbJSaxscSpsHwNaw8ztJIaVAerUIgKbudK
qr62B27394hKpFCAi40MPoy4sYUvRp6HqYs3crxILpmL97fJyK1boGAPSx0DaM87YZlzRCsODNOF
kQYbibyB9tL/+X9pjJaCC80fB0ile7T5eyS48FwJmJxw7c/+1nBCjL4PGeUdx7GAPRBGCbEvBBfC
wLnlvONrj6GwYR1W4WE69zjb88BBfui6exUErC4fGg2yb2qpcflb2LLp/lwCEt/sZopOQBtL/Sse
MB970IamZvCg688Gpv8OB21HW/QP2tCQlpzqCSPrm2KrTc41qliHtcrgq/ru4K2OsjSO8l8vsu3q
KFXyFH2jk2E6utLzwCoy56htz6/gMyPLlX9Ef4IfM0ks4JWhB6NIfZiNAXtXzk4sAa3HhJhe5IBL
7FHbz9orGC/AnYPaGJaVIFngGlnPRZaPHkYWPUkqor+N6T8pBjMFB7Y1GWop1p+xW81RuMjv3ytb
rKixxSLC3LjZFhsXRkWCvK+LtK8j8luNKMOPWy0NOKsPIHwrDpyIbhBPWCFJA5RFf7InvD0SE8uL
YZy0EvHyoMFZvtxqmPc3/DGWKZZkL8aURKeep2MP6Bfzkc4XkU4J8LbBnD7EzpyBzTlyaWq/vRMB
oLTTjp59EhpzZPo0yaTj2peGsO6jCDOwXsj7H3XiCsHbTpyptT2Ws6MguFusa7xJwieNjggJ+PXi
GYnoYBBMoBJS+AsCvIkESVxIdsWjJaXxxfXV5PxNR7X+/Orbl9ffXf40/qFN+MDums3LetGql7MO
aeFcHYLztNsBXmR21zPGli3ajdpBECxX03ndOjgsT8i6zlY1KwkOn85vyWEpbsDIdI71ZYbTrUm9
qLOZbM8/1Wx9QA5Ji2vGn1a7MzmOwg6ZwP/xjM1beH/WhsmrxYpMUdkqm9+yFoX29klA4M9etbh9
c5cd/AcK7QLRoRUAAA==
EOF

jorritfolmer avatar Aug 02 '17 14:08 jorritfolmer

Does your processing rate improve if you remove the mutate filter and output to a file with json_lines?

jorritfolmer avatar Aug 02 '17 15:08 jorritfolmer

What memory and heap settings are you using @jorritfolmer? My scaling from 4vCPU (1050 f/s) to 8vCPU (1930 f/s) is pretty dismal (with a single core, you're almost getting what I'm getting with 8!). I've now tried increasing memory and heap within the VM as well (2 GB mem 1GB heap > 4GB mem 2GB heap), without effect.

I'm still trying to get your script decoded and placed into a clean environment for further testing.

curl -XGET http://localhost:9600/_node/hot_threads?pretty=true&threads=10
 {
  "host" : "blah",
  "version" : "5.5.1",
  "http_address" : "127.0.0.1:9600",
  "id" : "1fc0627e-1a59-4e72-9bde-2e7aed695a03",
  "name" : "blah",
  "hot_threads" : {
    "time" : "2017-08-02T15:17:01-05:00",
    "busiest_threads" : 3,
    "threads" : [ {
      "name" : "Ruby-0-Thread-3",
      "percent_of_cpu_time" : 0.02,
      "state" : "timed_waiting",
      "path" : "/usr/share/logstash/vendor/bundle/jruby/1.9/gems/stud-0.0.22/lib/stud/task.rb:22",
      "traces" : [ "java.lang.Object.wait(Native Method)", "org.jruby.RubyThread.sleep(RubyThread.java:1002)", "org.jruby.RubyKernel.sleep(RubyKernel.java:803)" ]
    }, {
      "name" : "<udp.0",
      "percent_of_cpu_time" : 73.8,
      "state" : "runnable",
      "traces" : [ "org.joni.ByteCodeMachine.matchAt(ByteCodeMachine.java:306)", "org.joni.Matcher.matchCheck(Matcher.java:304)", "org.joni.Matcher.searchInterruptible(Matcher.java:457)" ]
    }, {
      "name" : "<udp.3",
      "percent_of_cpu_time" : 74.52,
      "state" : "runnable",
      "traces" : [ "java.lang.ThreadLocal.get(ThreadLocal.java:161)", "java.lang.StringCoding.deref(StringCoding.java:63)", "java.lang.StringCoding.decode(StringCoding.java:179)" ]
    } ]
  }
}

jasonkeller avatar Aug 02 '17 20:08 jasonkeller

Unfortunately doing a null output and/or removing the filter have zero appreciable impact.

jasonkeller avatar Aug 02 '17 20:08 jasonkeller

Weird. Except for the receive buffers and workers I haven't modified anything.

  • jvm.options is default, grep -v ^# jvm.options gives:
    -Xms256m
    -Xmx1g
    -XX:+UseParNewGC
    -XX:+UseConcMarkSweepGC
    -XX:CMSInitiatingOccupancyFraction=75
    -XX:+UseCMSInitiatingOccupancyOnly
    -XX:+DisableExplicitGC
    -Djava.awt.headless=true
    -Dfile.encoding=UTF-8
    -XX:+HeapDumpOnOutOfMemoryError
    
  • logstash.yml is unmodified, grep -v ^# logstash.yml gives:
    path.data: /var/lib/logstash
    path.config: /etc/logstash/conf.d
    path.logs: /var/log/logstash
    

For testing I used this conf, and the sysctl setting:

input {
  udp {
    port                 => 2055
    receive_buffer_bytes => 16777216
    codec                => netflow
    workers              => 6
  }
}

output {
  file { codec => "json_lines" path => "/tmp/netflowjson.log" }
}

The VM on my laptop has 2G and 4 vCPU The AWS box had 30G and 16 vCPU's.

jorritfolmer avatar Aug 02 '17 20:08 jorritfolmer

Strange indeed; at stock heap settings I'm hitting an absolute wall at around 1100 flows/s, whether I have workers on 6 or 8 (with 8vCPU). Something funky with garbage collection?

jasonkeller avatar Aug 02 '17 21:08 jasonkeller

Enlarging initial heap did increase the overall throughput to about 1620 flows/s with 6 workers. I hit 1878 flows/s with 8 workers. Enlarging it further seems to have no effect though.

jvm.options
-Xms1g
-Xmx1g

jasonkeller avatar Aug 02 '17 21:08 jasonkeller

Java version? I'm on 1.8.0-openjdk-headless, the Red Hat provided rpms.

Perhaps the flows/sec metric is flawed, and we should consider using other metrics to better compare different environments, like:

  • fields/sec: netflow_bench.py sends packets with 21 flows, with 26 fields per flow = 546 fields. Your PA sends packets with 8 flows, with an unknown number of fields. I'm assuming one of these fields contains urls for DPI-like monitoring, which are long, and make comparing fields/sec apples-oranges again.
  • Mbps: perhaps this is the most common denominator, since it just measures raw volume and doesn't care about distribution in fields or flows.

For the Amazon box, this would yield:

UDP workers Mbps
1 0.8
2 1.5
4 2.4
6 3.1
8 3.1
16 3.1

BTW: can you share one tpl and one data packet of your PA traffic? Or is it production? Email in my profile. I'd also like to this to the library of known-working exporters we test this codec with. (See the spec/codecs directory for others.

jorritfolmer avatar Aug 03 '17 07:08 jorritfolmer

Same here; Red Hat provided OpenJDK RPMs off our satellite

java -version
openjdk version "1.8.0_141"
OpenJDK Runtime Environment (build 1.8.0_141-b16)
OpenJDK 64-Bit Server VM (build 25.141-b16, mixed mode)

javac -version
javac 1.8.0_141-debug

iftop registers anywhere from 4.8 to 6.2 Mbit on average coming from the PA firewall.

I'd love to share the packet capture, but unfortunately this is off of a production stream that I won't be able to post. You are correct that there are two Palo Alto specific fields being exported (string), one is User-ID, the other is App-ID. Both are fairly short strings (usually not more than 10 characters or so).

However, I can share the netflow.yml file I edited to decode the additional fields...

---
1:
- 4
- :in_bytes
2:
- 4
- :in_pkts
3:
- 4
- :flows
4:
- :uint8
- :protocol
5:
- :uint8
- :src_tos
6:
- :uint8
- :tcp_flags
7:
- :uint16
- :l4_src_port
8:
- :ip4_addr
- :ipv4_src_addr
9:
- :uint8
- :src_mask
10:
- 2
- :input_snmp
11:
- :uint16
- :l4_dst_port
12:
- :ip4_addr
- :ipv4_dst_addr
13:
- :uint8
- :dst_mask
14:
- 2
- :output_snmp
15:
- :ip4_addr
- :ipv4_next_hop
16:
- 2
- :src_as
17:
- 2
- :dst_as
18:
- :ip4_addr
- :bgp_ipv4_next_hop
19:
- 4
- :mul_dst_pkts
20:
- 4
- :mul_dst_bytes
21:
- :uint32
- :last_switched
22:
- :uint32
- :first_switched
23:
- 4
- :out_bytes
24:
- 4
- :out_pkts
25:
- :uint16
- :min_pkt_length
26:
- :uint16
- :max_pkt_length
27:
- :ip6_addr
- :ipv6_src_addr
28:
- :ip6_addr
- :ipv6_dst_addr
29:
- :uint8
- :ipv6_src_mask
30:
- :uint8
- :ipv6_dst_mask
31:
- :uint24
- :ipv6_flow_label
32:
- :uint16
- :icmp_type
33:
- :uint8
- :mul_igmp_type
34:
- :uint32
- :sampling_interval
35:
- :uint8
- :sampling_algorithm
36:
- :uint16
- :flow_active_timeout
37:
- :uint16
- :flow_inactive_timeout
38:
- :uint8
- :engine_type
39:
- :uint8
- :engine_id
40:
- 4
- :total_bytes_exp
41:
- 4
- :total_pkts_exp
42:
- 4
- :total_flows_exp
43:
- :skip
44:
- :ip4_addr
- :ipv4_src_prefix
45:
- :ip4_addr
- :ipv4_dst_prefix
46:
- :uint8
- :mpls_top_label_type
47:
- :uint32
- :mpls_top_label_ip_addr
48:
- 4
- :flow_sampler_id
49:
- :uint8
- :flow_sampler_mode
50:
- :uint32
- :flow_sampler_random_interval
51:
- :skip
52:
- :uint8
- :min_ttl
53:
- :uint8
- :max_ttl
54:
- :uint16
- :ipv4_ident
55:
- :uint8
- :dst_tos
56:
- :mac_addr
- :in_src_mac
57:
- :mac_addr
- :out_dst_mac
58:
- :uint16
- :src_vlan
59:
- :uint16
- :dst_vlan
60:
- :uint8
- :ip_protocol_version
61:
- :uint8
- :direction
62:
- :ip6_addr
- :ipv6_next_hop
63:
- :ip6_addr
- :bgp_ipv6_next_hop
64:
- :uint32
- :ipv6_option_headers
65:
- :skip
66:
- :skip
67:
- :skip
68:
- :skip
69:
- :skip
80:
- :mac_addr
- :in_dst_mac
81:
- :mac_addr
- :out_src_mac
82:
- :string
- :if_name
83:
- :string
- :if_desc
84:
- :string
- :sampler_name
85:
- :uint32
- :in_permanent_bytes
86:
- :uint32
- :in_permanent_pkts
89:
- :forwarding_status
- :forwarding_status
94:
- :string
- :application_description
95:
- :application_id
- :application_id
96:
- :string
- :application_name
136:
- :uint8
- :flow_end_reason
148:
- :uint32
- :conn_id
152:
- 8
- :flow_start_msec
176:
- :uint8
- :icmp_type
177:
- :uint8
- :icmp_code
178:
- :uint8
- :icmp_type_ipv6
179:
- :uint8
- :icmp_code_ipv6
180:
- :uint16
- :udp_src_port
181:
- :uint16
- :udp_dst_port
182:
- :uint16
- :tcp_src_port
183:
- :uint16
- :tcp_dst_port
194:
- :uint8
- :ip_tos
195:
- :uint8
- :ip_dscp
201:
- mpls_label_stack_octets
- mpls_label_stack_octets
225:
- :ip4_addr
- :xlate_src_addr_ipv4
226:
- :ip4_addr
- :xlate_dst_addr_ipv4
227:
- :uint16
- :xlate_src_port
228:
- :uint16
- :xlate_dst_port
231:
- :uint32 
- :fwd_flow_delta_bytes
232:
- :uint32
- :rev_flow_delta_bytes
233:
- :uint8
- :fw_event
234:
- :uint32
- :ingressVRFID
235:
- :uint32
- :egressVRFID
236:
- :string
- :VRFname
281:
- :ip6_addr
- :xlate_src_addr_ipv6
282:
- :ip6_addr
- :xlate_dst_addr_ipv6
298:
- :uint64
- :initiatorPackets
299:
- :uint64
- :responderPackets
323:
- 8
- :event_time_msec
346:
- :skip
361:
- :uint16
- :postNATPortBlockStart
362:
- :uint16
- :postNATPortBlockEnd
8192:
- :uint32
- :streamcore_wan_rtt
8193:
- :uint32
- :streamcore_net_app_resp_time
8194:
- :uint32
- :streamcore_total_app_resp_time
8195:
- :uint16
- :streamcore_tcp_retrans_rate
8196:
- :uint8
- :streamcore_call_direction
8256:
- :string
- :streamcore_hostname
8257:
- :string
- :streamcore_url
8258:
- :string
- :streamcore_ssl_cn
8259:
- :string
- :streamcore_ssl_org
8320:
- :uint16
- :streamcore_mos_lq
8321:
- :uint16
- :streamcore_net_delay
8322:
- :uint16
- :streamcore_net_loss
8323:
- :uint16
- :streamcore_net_jitter
8324:
- :uint16
- :streamcore_net_discard
8325:
- :uint8
- :streamcore_rtp_clockrate_in
8326:
- :uint8
- :streamcore_rtp_clockrate_out
8327:
- :uint8
- :streamcore_codec_in
8328:
- :uint8
- :streamcore_codec_out
8384:
- :uint32
- :streamcore_id_rule_1
8385:
- :uint32
- :streamcore_id_rule_2
8386:
- :uint32
- :streamcore_id_rule_3
8387:
- :uint32
- :streamcore_id_rule_4
8388:
- :uint32
- :streamcore_id_rule_5
8389:
- :uint32
- :streamcore_id_rule_6
8390:
- :uint32
- :streamcore_id_rule_7
8391:
- :uint32
- :streamcore_id_rule_8
8392:
- :uint32
- :streamcore_id_rule_9
8393:
- :uint32
- :streamcore_id_rule_10
33000:
- :acl_id_asa
- :ingress_acl_id
33001:
- :acl_id_asa
- egress_acl_id
33002:
- :uint16
- :fw_ext_event
40000:
- :string
- :username
40001:
- :ip4_addr
- :xlate_src_addr_ipv4
40002:
- :ip4_addr
- :xlate_dst_addr_ipv4
40003:
- :uint16
- :xlate_src_port
40004:
- :uint16
- :xlate_dst_port
40005:
- :uint8
- :fw_event
56701:
- :string
- :app_id
56702:
- :string
- :user_id

And I can share the sanitized template packet...

Frame 5: 782 bytes on wire (6256 bits), 782 bytes captured (6256 bits)
    Encapsulation type: Ethernet (1)
    Arrival Time: Aug  2, 2017 08:42:41.422313000 Central Daylight Time
    [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1501681361.422313000 seconds
    [Time delta from previous captured frame: 0.000006000 seconds]
    [Time delta from previous displayed frame: 0.000006000 seconds]
    [Time since reference or first frame: 0.000346000 seconds]
    Frame Number: 5
    Frame Length: 782 bytes (6256 bits)
    Capture Length: 782 bytes (6256 bits)
    [Frame is marked: False]
    [Frame is ignored: False]
    [Protocols in frame: eth:ethertype:ip:udp:cflow]
    [Coloring Rule Name: UDP]
    [Coloring Rule String: udp]
Ethernet II, Src: PaloAlto_xx:xx:xx (b4:0c:25:xx:xx:xx), Dst: Vmware_xx:xx:xx (00:50:56:xx:xx:xx)
    Destination: Vmware_xx:xx:xx (00:50:56:xx:xx:xx)
    Source: PaloAlto_xx:xx:xx (b4:0c:25:xx:xx:xx)
    Type: IPv4 (0x0800)
Internet Protocol Version 4, Src: 10.xxx.xxx.xxx, Dst: 10.xxx.xxx.xxx
    0100 .... = Version: 4
    .... 0101 = Header Length: 20 bytes (5)
    Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
    Total Length: 768
    Identification: 0x0000 (0)
    Flags: 0x02 (Don't Fragment)
    Fragment offset: 0
    Time to live: 59
    Protocol: UDP (17)
    Header checksum: 0xa694 [validation disabled]
    [Header checksum status: Unverified]
    Source: 10.xxx.xxx.xxx
    Destination: 10.xxx.xxx.xxx
    [Source GeoIP: Unknown]
    [Destination GeoIP: Unknown]
User Datagram Protocol, Src Port: 57177, Dst Port: 2055
    Source Port: 57177
    Destination Port: 2055
    Length: 748
    Checksum: 0x2693 [unverified]
    [Checksum Status: Unverified]
    [Stream index: 0]
Cisco NetFlow/IPFIX
    Version: 9
    Count: 8
    SysUptime: 1490562.704000000 seconds
    Timestamp: Aug  2, 2017 08:42:41.000000000 Central Daylight Time
    FlowSequence: 198012671
    SourceId: 1
    FlowSet 1 [id=0] (Data Template): 256
    FlowSet 2 [id=0] (Data Template): 260
    FlowSet 3 [id=0] (Data Template): 258
    FlowSet 4 [id=0] (Data Template): 262
	FlowSet 5 [id=0] (Data Template): 257
    FlowSet Id: Data Template (V9) (0)
    FlowSet Length: 88
    Template (Id = 257, Count = 20)
        Template Id: 257
        Field Count: 20
        Field (1/20): BYTES
            Type: BYTES (1)
            Length: 8
        Field (2/20): PKTS
            Type: PKTS (2)
            Length: 4
        Field (3/20): PROTOCOL
            Type: PROTOCOL (4)
            Length: 1
        Field (4/20): IP_TOS
            Type: IP_TOS (5)
            Length: 1
        Field (5/20): TCP_FLAGS
            Type: TCP_FLAGS (6)
            Length: 1
        Field (6/20): L4_SRC_PORT
            Type: L4_SRC_PORT (7)
            Length: 2
        Field (7/20): IP_SRC_ADDR
            Type: IP_SRC_ADDR (8)
            Length: 4
        Field (8/20): INPUT_SNMP
            Type: INPUT_SNMP (10)
            Length: 4
        Field (9/20): L4_DST_PORT
            Type: L4_DST_PORT (11)
            Length: 2
        Field (10/20): IP_DST_ADDR
            Type: IP_DST_ADDR (12)
            Length: 4
        Field (11/20): OUTPUT_SNMP
            Type: OUTPUT_SNMP (14)
            Length: 4
        Field (12/20): LAST_SWITCHED
            Type: LAST_SWITCHED (21)
            Length: 4
        Field (13/20): FIRST_SWITCHED
            Type: FIRST_SWITCHED (22)
            Length: 4
        Field (14/20): ICMP_TYPE
            Type: ICMP_TYPE (32)
            Length: 2
        Field (15/20): DIRECTION
            Type: DIRECTION (61)
            Length: 1
        Field (16/20): flowId
            Type: flowId (148)
            Length: 8
        Field (17/20): firewallEvent
            Type: firewallEvent (233)
            Length: 1
        Field (18/20): privateEnterpriseNumber
            Type: privateEnterpriseNumber (346)
            Length: 4
        Field (19/20): Unknown(56701)
            Type: Unknown (56701)
            Length: 32
        Field (20/20): Unknown(56702)
            Type: Unknown (56702)
            Length: 64
    FlowSet 6 [id=0] (Data Template): 261
    FlowSet 7 [id=0] (Data Template): 259
    FlowSet 8 [id=0] (Data Template): 263

jasonkeller avatar Aug 03 '17 14:08 jasonkeller

I attempted to disable the additional fields for User-ID and App-ID, and it bumped my processing rate only around 100 flows/s. So it does not appear that the fields themselves are causing the performance issue.

jasonkeller avatar Aug 03 '17 14:08 jasonkeller

Are you sure the netflow codec is the bottleneck? There can be other places logstash slows down (waiting on elasticsearch, other filters, etc).

As a first guess, maybe look at your elasticsearch cluster and see if it needs more resources?

On Thu, Aug 3, 2017 at 7:38 AM Jason [email protected] wrote:

I attempted to disable the additional fields for User-ID and App-ID, and it bumped my processing rate only around 100 flows/s. So it does not appear that the fields themselves are causing the performance issue.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/logstash-plugins/logstash-codec-netflow/issues/85#issuecomment-319988567, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIC6mVShjlXv95aiO0nFVNm-pRJyghWks5sUdt6gaJpZM4OqGb- .

jordansissel avatar Aug 03 '17 16:08 jordansissel

@jordansissel we did narrow it down to the netflow codec. The filter was removed to no effect, as was the elasticsearch output. Removing the netflow codec for just a plain UDP input it can ingest all UDP packets without issue with about 17% CPU usage.

Elasticsearch is verified that it is not under stress, and has an optimized time series template for aggregations without a ton of indexing (and practically zero string tokenization).

jasonkeller avatar Aug 03 '17 18:08 jasonkeller

So I have an install in my clean room environment now.

  • vSphere 6.5 5969303
  • IBM HS23 (2x E5-2670, 96GB, 20 Gbit software iSCSI, all firmware up to date)
  • VM (VM version 13, 8vCPU, 8GB RAM, 100GB thin-provisioned disk)
  • An entire up-to-date ELKG stack is built onto it.
root@elk1:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:        16.04
Codename:       xenial
root@elk1:~# java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

Without tweaks (other than buffers and workers => 6) , I get approximately 3500 flows/s. With tweaking the lower bound on the java heap to 1g, I get around 4400 flows/s. These are graphed straight from the logstash metrics plugin via Grafana. Interesting thing to note is that my CPU is currently not above 50% in the VM.

image image

Compared to what I'm getting in prod, which is on better hardware (more oversubscribed, but also does not have any complications of having anything else installed on the same VM). CPU is around 75% (8vCPU, 4GB RAM)...

image

jasonkeller avatar Aug 03 '17 19:08 jasonkeller

Now here's something far more interesting... image

So this was taken with again what we'll call "stock" settings (no changes to heap, just buffers and workers => 6). Why the big difference (nearly 1000 flows/s more)? I changed the core layout in vSphere from 8 sockets to 2 sockets and 4 cores per socket. I'm still digging for more info as this used to set the vNUMA topology differently, however in 6.5 this may not affect the vNUMA layout.

jasonkeller avatar Aug 03 '17 20:08 jasonkeller

Just broke 6300 flows/s in the clean-room VM. image

Tuned as 1 socket 8 core per, with 6 workers, maxed out UDP buffers, and -Xms1g -Xmx1g set in jvm.options. CPU usage is now 86-87% in the guest OS.

jasonkeller avatar Aug 03 '17 20:08 jasonkeller