salt icon indicating copy to clipboard operation
salt copied to clipboard

Feature request - more robust console returner

Open eugenea opened this issue 13 years ago • 20 comments

Please change console returner from TCP based service to persistent ZMQ push-pull socket. This is why:

  • tcp service does not scale well, when number of clients surpasses 700 returner starts to lose 20-40% returns, and linux kernel complains on TCP syn flood on returner port. This is for sure not going to scale to 10k clients.
  • tcp service is not authenticated so you cannot trust the data you see.
  • ZMQ push pull socket has advantage of specifying multiple targets meaning that it can be used in cluster and HA mode,
  • ZMQ push pull socket will maintain connection open and there is no need to go through thousands of costly TCP handshakes after executing of every single command.

When console returner becomes authenticated and robust it makes sense to switch other returners to work OVER console returner because for example redis has no authentication, mysql has weak authentication known to have bugs in past, it is better to not expose database services all over accross the network. Perhaps having redis for job cache might become default solution, but redis should only listen on 127.0.0.1 interface.

eugenea avatar Mar 14 '13 17:03 eugenea

I am sorry I missed this, is this about the redis returner?

thatch45 avatar May 28 '13 23:05 thatch45

Well yes it could be a redis returner, or maybe some ZMQ socket back to master. The simple TCP server on the master does not work very well when 500 clients try to connect to it all at once.

From: Thomas S Hatch [mailto:[email protected]] Sent: Tuesday, May 28, 2013 4:53 PM To: saltstack/salt Cc: Eugene Aleynikov Subject: Re: [salt] Feature request - more robust console returner (#4106)

I am sorry I missed this, is this about the redis returner?

— Reply to this email directly or view it on GitHubhttps://github.com/saltstack/salt/issues/4106#issuecomment-18587855.

eugenea avatar May 29 '13 00:05 eugenea

I don't understand, all of the transport for Salt communication is ZeroMQ, the connection back to the master is ZeroMQ, it is tested regularly well beyond 500 clients up into the 10,000+ range. What "plain TCP" connection are you referring to?

thatch45 avatar May 29 '13 01:05 thatch45

When I execute some command I get “DDos detected, enabling syn cookies” on the server. Which means that clients are trying to connect to the server via tcp during command execution. I also lose response from about 40% of the client. With latest version of salt the problem got much better. But in 13.1 when you specify –b option you would lose response from about 40% clients still.

I haven’t tested it with 0.14 but I can if you need me to.

From: Thomas S Hatch [mailto:[email protected]] Sent: Tuesday, May 28, 2013 6:01 PM To: saltstack/salt Cc: Eugene Aleynikov Subject: Re: [salt] Feature request - more robust console returner (#4106)

I don't understand, all of the transport for Salt communication is ZeroMQ, the connection back to the master is ZeroMQ, it is tested regularly well beyond 500 clients up into the 10,000+ range. What "plain TCP" connection are you referring to?

— Reply to this email directly or view it on GitHubhttps://github.com/saltstack/salt/issues/4106#issuecomment-18590073.

eugenea avatar May 29 '13 17:05 eugenea

Where is the DDos detected coming from? Also, what version of zeromq are you using, zeromq uses tcp for the transport. It sounds like some other system is dropping the TCP connections, what OS are you running? Also, whatever is detecting DDos should be told that this is expected behavior

thatch45 avatar May 29 '13 18:05 thatch45

From the kernel which is seeing too many SYN packets all at once. (dmesg)

[6219779.986931] possible SYN flooding on port 4506. Sending cookies. [6219911.711929] possible SYN flooding on port 4506. Sending cookies. [6398179.617532] possible SYN flooding on port 4506. Sending cookies. [6398249.518311] possible SYN flooding on port 4506. Sending cookies. [6399873.620682] possible SYN flooding on port 4506. Sending cookies. [6637583.299480] possible SYN flooding on port 4506. Sending cookies.

The backlog is set to 2k Here’s my sysctl tunables:

net.ipv6.conf.all.disable_ipv6=1 net.core.rmem_max=131071 net.core.wmem_max=131071 net.ipv4.tcp_rmem=4096 87380 4194304 net.ipv4.tcp_wmem=4096 16384 4194304 net.core.somaxconn = 1024 net.ipv4.tcp_max_syn_backlog = 2048 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_keepalive_time = 290 net.ipv4.tcp_keepalive_probes = 3

which means that when I execute command salt master receive more than 2k TCP connects all at once.

When kernel fills up SYN backlog it is switching to SYN cookies and it tells about it.

OS is debian squeeze. The ZMQ version is 2.2.0+dfsg-2~bpo60+1 (from squeeze backports).

From: Thomas S Hatch [mailto:[email protected]] Sent: Wednesday, May 29, 2013 11:02 AM To: saltstack/salt Cc: Eugene Aleynikov Subject: Re: [salt] Feature request - more robust console returner (#4106)

Where is the DDos detected coming from? Also, what version of zeromq are you using, zeromq uses tcp for the transport. It sounds like some other system is dropping the TCP connections, what OS are you running? Also, whatever is detecting DDos should be told that this is expected behavior

— Reply to this email directly or view it on GitHubhttps://github.com/saltstack/salt/issues/4106#issuecomment-18634749.

eugenea avatar May 29 '13 18:05 eugenea

Hmmm, there are a lot of connections being made, I also think that bumping up to ZeroMQ 3 will help, we had a lot of problems with ZeroMQ 2, I think that there are ZeroMQ 3 packages in debian.saltstack.com

thatch45 avatar May 29 '13 18:05 thatch45

Bumping to zmq3 will be very hard. You need to relink pyzmq (you use it right?) with it and then other stuff that uses ZMQ will break.

From: Thomas S Hatch [mailto:[email protected]] Sent: Wednesday, May 29, 2013 11:19 AM To: saltstack/salt Cc: Eugene Aleynikov Subject: Re: [salt] Feature request - more robust console returner (#4106)

Hmmm, there are a lot of connections being made, I also think that bumping up to ZeroMQ 3 will help, we had a lot of problems with ZeroMQ 2, I think that there are ZeroMQ 3 packages in debian.saltstack.com

— Reply to this email directly or view it on GitHubhttps://github.com/saltstack/salt/issues/4106#issuecomment-18635808.

eugenea avatar May 29 '13 18:05 eugenea

I’m not completely understand though how bumping ZMQ version will help the problem that all clients are trying to connect all at once. With ZMQ2 version you can connect before you execute command and have no such problem. But from someone on SALT IRC I heard that ZMQ is not even being used for console returner, it is plain TCP server, but don’t quote me on that.

From: Thomas S Hatch [mailto:[email protected]] Sent: Wednesday, May 29, 2013 11:19 AM To: saltstack/salt Cc: Eugene Aleynikov Subject: Re: [salt] Feature request - more robust console returner (#4106)

Hmmm, there are a lot of connections being made, I also think that bumping up to ZeroMQ 3 will help, we had a lot of problems with ZeroMQ 2, I think that there are ZeroMQ 3 packages in debian.saltstack.com

— Reply to this email directly or view it on GitHubhttps://github.com/saltstack/salt/issues/4106#issuecomment-18635808.

eugenea avatar May 29 '13 18:05 eugenea

@eugenea You might be surprised at the problems that arise because of ZMQ2 -- dropped minions is the biggest. Upgrading to ZMQ3 is a must if you want Salt's connection to the minions to be as robust as it needs to be.

That said, your problem is still a weird one, with all those TCP connections being made.

Oh, and to comment on your last statement, I think the person you heard on Salt IRC may be right, but dont' quote me on that either, because I am not very familiar with ZMQ.

basepi avatar May 29 '13 20:05 basepi

Trying to understand this, as we notice slowness, dropped minion ('Minion did not return'). Looks like salt minion open a fresh connection to master return port (default: 4506/tcp) for every request such as get a salt state file, etc. One can view via. 'lsof -n -i:4506 | grep ESTABLISHED' and see number of connections growing from a same minion when issuing a single salt command. (I was expecting a single return connection for a single salt job, but that is not the case for now).

It further depends upon how the state system is designed. For example if there are 50 state files, to be downloaded to 500 minions (for a command like "salt '*' state.highstate"), then salt master is going to get (50 * 500 = 25,000) connection requests at the minimum, plus connection requests for additional files to be downloaded via state logic. I noticed lsof showed up to 3500 connections on our master from minions at a time, so looks like zmq is trying to balance out in order to cater thousands of connections requested from minions to master and slow down the execution (This is my guess, may be I am wrong here). If this communication can be improved, then it would be a big help for large installs with lot of state files.

I am also trying to tinker fileclient.py on minions and adding a logic for 'class RemoteClient.get_file()' , to match hash for a file between local minion cache vs file on the master server and skip file download if the file didn't change. This doesn't reduce the number of calls made from minion to master (as it still need to query for a hash of a file via fresh salt connection) and may increase CPU usage on master side for all those hash calculation. If this helps, then I would send my patch upstream. On LAN this isn't helping much as state files are not large, but on WAN it is showing little better results. But most of the time master is busy and bogged down with the thousands of connection requests from minions. Indeed if we use cache=True option (like : salt '*' state.highstate cache=True) , the execution is several fold faster (14x in our case), as minions/master are less busy chatting, skipping calls for file downloads entirely. But using cache=True is not practical all the time.

Some data points. single state.sls execution time: 42seconds (w/ cache=True), 10+minutes(w/o cache=True) state.highstate execution rime: 5 minutes (w/ cache=True), 65minutes(w/o cache=True)

mlister2006 avatar Aug 02 '13 15:08 mlister2006

I'm seeing something that may be related to this. It doesn't seem salt-run wants to run against more than 999 minions. When it attempts to I'm seeing the possible SYN flooding on port 4506. Sending cookies. message. I'm running 0.17.5 with zmq 3.2.4. Can't run 2014.1.0 due to the multi-master issue. Currently debugging but was any more info found on this?

replicant0wnz avatar Mar 26 '14 15:03 replicant0wnz

Examples:

master1]~❯ sudo salt-run -t 20 manage.up | wc -l
999
master1]~❯ sudo salt-run -t 20 manage.down | wc -l
23
master1]~❯ sudo ls -1 /etc/salt/pki/master/minions | wc -l
1022
master1]~❯ dmesg | grep SYN
possible SYN flooding on port 4506. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.

replicant0wnz avatar Mar 26 '14 15:03 replicant0wnz

Nope i was running it in AWS where i had only 2 minions.

eugenea avatar Mar 26 '14 16:03 eugenea

FYI starting with 2014.* versions this situation got worse.

eugenea avatar May 08 '14 22:05 eugenea

I have hit this issue too, I have 2000+ nodes and on startup they issue a highstate and it looks like they are killing my master.

[[email protected]]~% salt --versions-report 
           Salt: 2014.1.4
         Python: 2.6.6 (r266:84292, Nov 21 2013, 10:50:32)
         Jinja2: 2.2.1
       M2Crypto: 0.20.2
 msgpack-python: 0.1.13
   msgpack-pure: Not Installed
       pycrypto: 2.0.1
         PyYAML: 3.10
          PyZMQ: 2.2.0.1
            ZMQ: 3.2.4
possible SYN flooding on port 4505. Sending cookies.
possible SYN flooding on port 4505. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.

dmyerscough avatar Sep 25 '14 23:09 dmyerscough

Anything new on this? I am seeing the same behavior. Added ~1000 clients, and about ~2min after bootup they end up killing my salt-master. (they don't actually kill it they essentially flood it off the network)

           Salt: 2014.7.1
         Python: 2.6.6 (r266:84292, Nov 21 2013, 12:39:37)
         Jinja2: 2.2.1
       M2Crypto: 0.20.2
 msgpack-python: 0.4.4
   msgpack-pure: Not Installed
       pycrypto: 2.0.1
        libnacl: Not Installed
         PyYAML: 3.10
          ioflo: Not Installed
          PyZMQ: 14.3.1
           RAET: Not Installed
            ZMQ: 3.2.4
           Mako: Not Installed
salt.x.com:
    ----------
    SSDs:
    biosreleasedate:
        07/30/2013
    biosversion:
        6.00
    cpu_flags:
        - fpu
        - vme
        - de
        - pse
        - tsc
        - msr
        - pae
        - mce
        - cx8
        - apic
        - sep
        - mtrr
        - pge
        - mca
        - cmov
        - pat
        - pse36
        - clflush
        - dts
        - mmx
        - fxsr
        - sse
        - sse2
        - ss
        - ht
        - syscall
        - nx
        - rdtscp
        - lm
        - constant_tsc
        - arch_perfmon
        - pebs
        - bts
        - xtopology
        - tsc_reliable
        - nonstop_tsc
        - aperfmperf
        - unfair_spinlock
        - pni
        - pclmulqdq
        - ssse3
        - cx16
        - sse4_1
        - sse4_2
        - popcnt
        - aes
        - xsave
        - avx
        - hypervisor
        - lahf_lm
        - ida
        - arat
        - epb
        - xsaveopt
        - pln
        - pts
        - dts
    cpu_model:
        Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz
    cpuarch:
        x86_64
    domain:
        x.com
    fqdn:
        salt.x.com
    fqdn_ip4:
        - x
    fqdn_ip6:
    gpus:
        |_
          ----------
          model:
              SVGA II Adapter
          vendor:
              unknown
    host:
        salt
    hwaddr_interfaces:
        ----------
        eth0:
            x
        lo:
            00:00:00:00:00:00
    id:
        salt.x.com
    ip4_interfaces:
        ----------
        eth0:
            - x
        lo:
            - 127.0.0.1
    ip6_interfaces:
        ----------
        eth0:
        lo:
    ip_interfaces:
        ----------
        eth0:
            - x
        lo:
            - 127.0.0.1
    ipv4:
        - x
        - 127.0.0.1
    ipv6:
    kernel:
        Linux
    kernelrelease:
        2.6.32-431.29.2.el6.x86_64
    locale_info:
        ----------
        defaultencoding:
            UTF8
        defaultlanguage:
            en_US
    localhost:
        salt.x.com
    machine_id:
        x
    manufacturer:
        VMware, Inc.
    master:
        salt
    mem_total:
        15951
    nodename:
        salt.centtech.com
    num_cpus:
        4
    num_gpus:
        1
    os:
        ScientificLinux
    os_family:
        RedHat
    osarch:
        x86_64
    oscodename:
        Carbon
    osfinger:
        Scientific Linux-6
    osfullname:
        Scientific Linux
    osmajorrelease:
        6
    osrelease:
        6.5
    osrelease_info:
        - 6
        - 5
    path:
        /sbin:/usr/sbin:/bin:/usr/bin
    productname:
        VMware Virtual Platform
    ps:
        ps -efH
    pythonexecutable:
        /usr/bin/python
    pythonpath:
        - /usr/bin
        - /usr/lib64/python26.zip
        - /usr/lib64/python2.6
        - /usr/lib64/python2.6/plat-linux2
        - /usr/lib64/python2.6/lib-tk
        - /usr/lib64/python2.6/lib-old
        - /usr/lib64/python2.6/lib-dynload
        - /usr/lib64/python2.6/site-packages
        - /usr/lib64/python2.6/site-packages/gtk-2.0
        - /usr/lib/python2.6/site-packages
        - /usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info
    pythonversion:
        - 2
        - 6
        - 6
        - final
        - 0
    saltpath:
        /usr/lib/python2.6/site-packages/salt
    saltversion:
        2014.7.1
    saltversioninfo:
        - 2014
        - 7
        - 1
        - 0
    selinux:
        ----------
        enabled:
            False
        enforced:
            Disabled
    serialnumber:
        VMware-42 23 1d 3b 62 11 11 ab-65 f7 65 10 4a cb ec e4
    server_id:
        996696352
    shell:
        /bin/sh
    virtual:
        VMware
    zmqversion:
        3.2.4

And from system messages...

Mar 1 20:33:31 salt kernel: possible SYN flooding on port 4506. Sending cookies.

preachermanx avatar Mar 02 '15 02:03 preachermanx

I use following script to trigger the issue

for i in `seq 3`; do  time salt-run manage.down |egrep -v "^-"; done

here is my saltmaster info.

[me@salt01 ~]$ cat /etc/sysctl.d/saltstack.conf
# https://github.com/saltstack/salt/issues/4106
net.core.somaxconn = 1024
net.ipv4.tcp_max_syn_backlog = 2048
net.ipv4.tcp_keepalive_time = 290
net.ipv4.tcp_keepalive_probes = 3
[me@salt01 ~]$

[me@salt01 ~]$ cat /etc/redhat-release
CentOS release 6.8 (Final)
[me@salt01 ~]$ salt-master --versions-report
Salt Version:
           Salt: 2016.3.1

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.7.3
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: 0.20.2
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
         pygit2: Not Installed
         Python: 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 14.5.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5

System Versions:
           dist: centos 6.8 Final
        machine: x86_64
        release: 2.6.32-642.1.1.el6.x86_64
         system: Linux
        version: CentOS 6.8 Final
[me@salt01 ~]$ tail -100 /var/log/messages|grep SYN
Jul  9 08:56:37 ilclsalt01 kernel: possible SYN flooding on port 4506. Sending cookies.
Jul  9 08:59:07 ilclsalt01 kernel: possible SYN flooding on port 4506. Sending cookies.
Jul  9 09:00:52 ilclsalt01 kernel: possible SYN flooding on port 4506. Sending cookies.
[me@salt01 ~]$
[me@salt01 ~]$ dmesg |grep SYN
possible SYN flooding on port 4506. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.
[me@salt01 ~]$
[me@salt01 ~]$ dmesg |grep SYN
possible SYN flooding on port 4506. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.
possible SYN flooding on port 4506. Sending cookies.
[me@salt01 ~]$ sudo ls -1 /etc/salt/pki/master/minions | wc -l
737
[me@salt01 ~]$ sudo lsof -n -i:4506 | grep ESTABLISHED |wc
    352    3520   36651
[me@salt01 ~]$

tjyang avatar Jul 09 '16 14:07 tjyang

Targeting same set of minions using different master.

  • stress test 3 runs on salt02 doesn't generate warning message anymore..
  • stress test 10 runs on salt02 (centos 7.2) using following script will still generate message.
 for i in `seq 10 `; do  time salt-run manage.down |egrep -v "^-"; done
  • with /etc/sysctl.d/saltstack.conf setting like following
[root@salt02 ~]# cat /etc/sysctl.d/saltstack.conf
# https://github.com/saltstack/salt/issues/4106
#net.core.somaxconn = 1024
net.core.somaxconn = 2048
#net.ipv4.tcp_max_syn_backlog = 2048
net.ipv4.tcp_max_syn_backlog = 4096
net.ipv4.tcp_keepalive_time = 290
net.ipv4.tcp_keepalive_probes = 3
[root@salt02 ~]#
  • Here is the flooding message after 10 runs of test.ping
[Sat Jul  9 16:07:24 2016] TCP: request_sock_TCP: Possible SYN flooding on port 4506. Sending cookies.  Check SNMP counters.
[root@salt02 ~]#
  • salt-master --versions-report
Salt Version:
           Salt: 2016.3.1

Dependency Versions:
           cffi: 0.8.6
       cherrypy: 3.2.2
       dateutil: 1.5
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: 0.21.0
        libnacl: Not Installed
       M2Crypto: 0.21.1
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.7
   mysql-python: Not Installed
      pycparser: 2.14
       pycrypto: 2.6.1
         pygit2: 0.21.4
         Python: 2.7.5 (default, Nov 20 2015, 02:00:19)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 14.7.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5

System Versions:
           dist: centos 7.2.1511 Core
        machine: x86_64
        release: 3.10.0-327.22.2.el7.x86_64
         system: Linux
        version: CentOS Linux 7.2.1511 Core

tjyang avatar Jul 09 '16 21:07 tjyang

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

stale[bot] avatar Jun 04 '18 19:06 stale[bot]