Join the community today
Register Now

Nginx nginx's UNIT

Discussion in 'Nginx and PHP-FPM news & discussions' started by Xon, Sep 8, 2017.

  1. Xon

    Xon Active Member

    173
    61
    28
    Nov 16, 2015
    Ratings:
    +229
    Local Time:
    11:34 AM
    1.15.x
    MariaDB 10.3.x
  2. rdan

    rdan Well-Known Member

    5,397
    1,353
    113
    May 25, 2014
    Ratings:
    +2,126
    Local Time:
    11:34 AM
    Mainline
    10.2
  3. Sunka

    Sunka Well-Known Member

    1,150
    323
    83
    Oct 31, 2015
    Pula, Croatia
    Ratings:
    +521
    Local Time:
    5:34 AM
    Nginx 1.17.9
    MariaDB 10.3.22
    This?
     
  4. eva2000

    eva2000 Administrator Staff Member

    49,875
    11,487
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,839
    Local Time:
    1:34 PM
    Nginx 1.21.x
    MariaDB 10.x
    Thanks for the heads up.. interesting developments Introducing the NGINX Application Platform with Controller and Unit :)

     
  5. buik

    buik “The best traveler is one without a camera.”

    1,783
    483
    83
    Apr 29, 2016
    Flanders
    Ratings:
    +1,527
    Local Time:
    5:34 AM
    Nginx plus, Nginx controller, Nginx unit, Nginx web application firewall..... Nginx http/2 server push uuuh.......... no of course not. It is crystal clear where Nginx's current priority is.

    Because VPS servers are getting cheaper and cheaper (race to the bottom),
    it is becoming increasingly attractive to run Apache.
     
  6. eva2000

    eva2000 Administrator Staff Member

    49,875
    11,487
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,839
    Local Time:
    1:34 PM
    Nginx 1.21.x
    MariaDB 10.x
    some of Nginx.conf 2017 videos make it clear where Nginx's future priorities are https://community.centminmod.com/threads/nginx-conf-2017-user-conference-youtube-playlist.12923/









    I started playing with Nginx Unit on Centmin Mod too via CentOS 7.4

    Code (Text):
    systemctl status unitd
    ● unitd.service - NGINX Unit
       Loaded: loaded (/usr/lib/systemd/system/unitd.service; disabled; vendor preset: disabled)
       Active: active (running) since Sat 2017-09-23 10:03:05 UTC; 1s ago
      Process: 10287 ExecStart=/opt/unit/sbin/unitd (code=exited, status=0/SUCCESS)
     Main PID: 10288 (unitd)
       CGroup: /system.slice/unitd.service
               ├─10288 unit: main [/opt/unit/sbin/unitd]
               ├─10290 unit: controller
               └─10291 unit: router
    
    Sep 23 10:03:05 centos7.localdomain systemd[1]: Starting NGINX Unit...
    Sep 23 10:03:05 centos7.localdomain unitd[10287]: 2017/09/23 10:03:05 [info] 10287#10287 unit started
    Sep 23 10:03:05 centos7.localdomain systemd[1]: Started NGINX Unit.
    

    Code (Text):
    root     10288  0.0  0.0  16028   604 ?        Ss   10:03   0:00 unit: main [/opt/unit/sbin/unitd]
    nginx    10290  0.0  0.0  16028   412 ?        S    10:03   0:00  \_ unit: controller
    nginx    10291  0.0  0.0  16028   416 ?        S    10:03   0:00  \_ unit: router
    

    Code (Text):
    /opt/unit/sbin/unitd --version
    unit version: 0.1
    configured as ./configure --prefix=/opt/unit --pid=/run/unitd.pid --log=/var/log/unitd.log --modules=modules --user=nginx --group=nginx --state=state
    

    Code (Text):
    curl -X PUT -d @/root/tools/unitconfigs/phpstart.json --unix-socket /opt/unit/control.unit.sock http://localhost/
    {
           "success": "Reconfiguration done."
    }
    

    Code (Text):
    curl --unix-socket /opt/unit/control.unit.sock http://localhost/
    {
           "listeners": {
                   "*:8300": {
                           "application": "php56domaincom"
                   }
           },
    
           "applications": {
                   "php56domaincom": {
                           "type": "php",
                           "workers": 10,
                           "root": "/home/nginx/domains/domain.com/public",
                           "user": "nginx",
                           "group": "nginx",
                           "index": "index.php"
                   }
           }
    }
    


    Nginx Unit PHP where Sever API = unit and compiled against Centmin Mod's PHP-FPM 5.6.31 so took on extensions and settings of the PHP-FPM 5.6.31 install too.

    nginx-unit-php5631-info-01.png
     
    Last edited: Sep 23, 2017
  7. nfn

    nfn New Member

    29
    0
    1
    Jun 28, 2015
    Ratings:
    +8
    Local Time:
    4:34 AM
    Just a small test between fastcgi and unit using phpinfo :)

    FastCGI:

    Code:
    # siege -b -c250 -t30s http://localhost:8080/i.php
    ** SIEGE 4.0.2
    ** Preparing 250 concurrent users for battle.
    The server is now under siege...
    Lifting the server siege...
    Transactions:                6856 hits
    Availability:              100.00 %
    Elapsed time:               29.66 secs
    Data transferred:          386.71 MB
    Response time:                1.06 secs
    Transaction rate:          231.15 trans/sec
    Throughput:               13.04 MB/sec
    Concurrency:              244.32
    Successful transactions:        6856
    Failed transactions:               0
    Longest transaction:            4.00
    Shortest transaction:            0.06
    Unit:

    Code:
    # siege -b -c250 -t30s http://localhost:8000/i.php
    ** SIEGE 4.0.2
    ** Preparing 250 concurrent users for battle.
    The server is now under siege...
    Lifting the server siege...
    Transactions:                7847 hits
    Availability:              100.00 %
    Elapsed time:               29.78 secs
    Data transferred:          428.59 MB
    Response time:                0.93 secs
    Transaction rate:          263.50 trans/sec
    Throughput:               14.39 MB/sec
    Concurrency:              245.69
    Successful transactions:        7847
    Failed transactions:               0
    Longest transaction:            1.24
    Shortest transaction:            0.05
    Good news for performance addict ;)
     
  8. eva2000

    eva2000 Administrator Staff Member

    49,875
    11,487
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,839
    Local Time:
    1:34 PM
    Nginx 1.21.x
    MariaDB 10.x
    ooh you beat me to the next phase - benchmark testing :D

    both php-fpm and Unit PHP using same number of php workers ?
     
  9. nfn

    nfn New Member

    29
    0
    1
    Jun 28, 2015
    Ratings:
    +8
    Local Time:
    4:34 AM
    My benchmarks are lights away from yours ;)

    Code:
    pm = dynamic
    pm.max_children = 50
    pm.start_servers = 5
    pm.min_spare_servers = 5
    pm.max_spare_servers = 35
    vs

    Code:
    "workers": 20
    I would prefer to see yours!
    These where made in a small hosthatch vps
     
  10. eva2000

    eva2000 Administrator Staff Member

    49,875
    11,487
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,839
    Local Time:
    1:34 PM
    Nginx 1.21.x
    MariaDB 10.x
    Well proper testing would have separate siege testing from target server. But for quick tests on same server is ok to get an idea.

    Quick local benchmarks with Centmin Mod 123.09beta01 and PHP-FPM 5.6.31 as well as Nginx Unit 0.1 with PHP configured with PHP 5.6.31. Haven't tested for cpu and memory resource usage differences yet.

    PHP-FPM 5.6.31 settings from php-fpm.conf with Nginx running on port 8080 with pm = ondemand
    Code (Text):
    pm = ondemand
    pm.max_children = 16
    ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
    pm.start_servers = 8
    pm.min_spare_servers = 4
    pm.max_spare_servers = 12
    pm.max_requests = 1000
    

    PHP-FPM 5.6.31 settings from php-fpm.conf with Nginx running on port 8080 with pm = static
    Code (Text):
    pm = static
    pm.max_children = 16
    ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
    pm.start_servers = 8
    pm.min_spare_servers = 4
    pm.max_spare_servers = 12
    pm.max_requests = 1000
    

    PHP-FPM 5.6.31 settings from php-fpm.conf with Nginx running on port 8080 with pm = dynamic
    Code (Text):
    pm = dynamic
    pm.max_children = 16
    ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
    pm.start_servers = 8
    pm.min_spare_servers = 4
    pm.max_spare_servers = 12
    pm.max_requests = 1000
    

    Nginx Unit 0.1 + PHP 5.6.31 settings running on port 8300
    Code (Text):
    curl --unix-socket /opt/unit/control.unit.sock http://localhost/applications/php56domaincom
    {
            "type": "php",
            "workers": 10,
            "root": "/home/nginx/domains/domain.com/public",
            "user": "nginx",
            "group": "nginx",
            "index": "index.php"
    }
    

    Code (Text):
     curl --unix-socket /opt/unit/control.unit.sock http://localhost/
    {
            "listeners": {
                    "*:8300": {
                            "application": "php56domaincom"
                    }
            },
    
            "applications": {
                    "php56domaincom": {
                            "type": "php",
                            "workers": 10,
                            "root": "/home/nginx/domains/domain.com/public",
                            "user": "nginx",
                            "group": "nginx",
                            "index": "index.php"
                    }
            }
    }
    

    PHP-FPM 5.6.31 settings from php-fpm.conf with Nginx running on port 8080 with pm = ondemand
    Code (Text):
    siege -b -c100 -t30s http://domain.com:8080/index.php -m cmm-nginx-php-fpm-5631
    Transactions:                   4289 hits
    Availability:                 100.00 %
    Elapsed time:                  29.33 secs
    Data transferred:             439.39 MB
    Response time:                  0.51 secs
    Transaction rate:             146.23 trans/sec
    Throughput:                    14.98 MB/sec
    Concurrency:                   74.78
    Successful transactions:        4303
    Failed transactions:               0
    Longest transaction:            2.20
    Shortest transaction:           0.02
    

    PHP-FPM 5.6.31 settings from php-fpm.conf with Nginx running on port 8080 with pm = static
    Code (Text):
    siege -b -c100 -t30s http://domain.com:8080/index.php -m cmm-nginx-php-fpm-5631-static-pm
    Transactions:                   4834 hits
    Availability:                 100.00 %
    Elapsed time:                  29.96 secs
    Data transferred:             495.96 MB
    Response time:                  0.48 secs
    Transaction rate:             161.35 trans/sec
    Throughput:                    16.55 MB/sec
    Concurrency:                   77.54
    Successful transactions:        4857
    Failed transactions:               0
    Longest transaction:            2.25
    Shortest transaction:           0.02
    

    PHP-FPM 5.6.31 settings from php-fpm.conf with Nginx running on port 8080 with pm = dynamic
    Code (Text):
    siege -b -c100 -t30s http://domain.com:8080/index.php -m cmm-nginx-php-fpm-5631-dynamic-pm
    Transactions:                   5134 hits
    Availability:                 100.00 %
    Elapsed time:                  30.10 secs
    Data transferred:             528.23 MB
    Response time:                  0.45 secs
    Transaction rate:             170.56 trans/sec
    Throughput:                    17.55 MB/sec
    Concurrency:                   77.22
    Successful transactions:        5173
    Failed transactions:               0
    Longest transaction:            2.38
    Shortest transaction:           0.03
    

    Nginx Unit 0.1 + PHP 5.6.31 settings running on port 8300
    Code (Text):
    siege -b -c100 -t30s http://domain.com:8300/index.php -m nginx-unit-php5631
    
    Transactions:                   8279 hits
    Availability:                 100.00 %
    Elapsed time:                  29.26 secs
    Data transferred:             818.82 MB
    Response time:                  0.35 secs
    Transaction rate:             282.95 trans/sec
    Throughput:                    27.98 MB/sec
    Concurrency:                   97.74
    Successful transactions:        8281
    Failed transactions:               0
    Longest transaction:            1.27
    Shortest transaction:           0.01
    

    Liking what I see for quick tests so far. Will be interesting to see how tuning PHP-FPM settings itself changes performance but just 10 workers in Nginx Unit based PHP is looking good !
    Code (Text):
    head -n1 /usr/local/var/log/siege.log; tail -8 /usr/local/var/log/siege.log
          Date & Time,  Trans,  Elap Time,  Data Trans,  Resp Time,  Trans Rate,  Throughput,  Concurrent,    OKAY,   Failed
    **** nginx-unit-php5631 ****
    2017-09-23 20:10:42,   8279,      29.26,         818,       0.35,      282.95,       27.96,       97.74,    8281,       0
    **** cmm-nginx-php-fpm-5631 ****
    2017-09-23 20:12:25,   4289,      29.33,         439,       0.51,      146.23,       14.97,       74.78,    4303,       0
    **** cmm-nginx-php-fpm-5631-static-pm ****
    2017-09-23 20:16:44,   4834,      29.96,         495,       0.48,      161.35,       16.52,       77.54,    4857,       0
    **** cmm-nginx-php-fpm-5631-dynamic-pm ****
    2017-09-23 20:20:50,   5134,      30.10,         528,       0.45,      170.56,       17.54,       77.22,    5173,       0
    


    Edit: add a tuned PHP-FPM dynamic PM with higher max children and spare

    PHP-FPM 5.6.31 settings from php-fpm.conf with Nginx running on port 8080 with pm = dynamic and raised max_children from 16 to 40 and max_spare_servers from 12 to 36
    Code (Text):
    pm = dynamic
    pm.max_children = 40
    ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
    pm.start_servers = 8
    pm.min_spare_servers = 4
    pm.max_spare_servers = 36
    pm.max_requests = 1000
    

    Code (Text):
    siege -b -c100 -t30s http://domain.com:8080/index.php -m cmm-nginx-php-fpm-5631-dynamic-pm-maxchild40-maxspare36
    Transactions:                   3581 hits
    Availability:                 100.00 %
    Elapsed time:                  29.85 secs
    Data transferred:             370.98 MB
    Response time:                  0.60 secs
    Transaction rate:             119.97 trans/sec
    Throughput:                    12.43 MB/sec
    Concurrency:                   72.45
    Successful transactions:        3633
    Failed transactions:               0
    Longest transaction:            4.94
    Shortest transaction:           0.02
    

    Did 2 runs just to be sure
    Code (Text):
    siege -b -c100 -t30s http://domain.com:8080/index.php -m cmm-nginx-php-fpm-5631-dynamic-pm-maxchild40-maxspare36-run2
    Transactions:                   4804 hits
    Availability:                 100.00 %
    Elapsed time:                  29.67 secs
    Data transferred:             497.09 MB
    Response time:                  0.37 secs
    Transaction rate:             161.91 trans/sec
    Throughput:                    16.75 MB/sec
    Concurrency:                   59.66
    Successful transactions:        4868
    Failed transactions:               0
    Longest transaction:            2.52
    Shortest transaction:           0.01
    

    Code (Text):
    head -n1 /usr/local/var/log/siege.log; tail -12 /usr/local/var/log/siege.log                                 
          Date & Time,  Trans,  Elap Time,  Data Trans,  Resp Time,  Trans Rate,  Throughput,  Concurrent,    OKAY,   Failed
    **** nginx-unit-php5631 ****
    2017-09-23 20:10:42,   8279,      29.26,         818,       0.35,      282.95,       27.96,       97.74,    8281,       0
    **** cmm-nginx-php-fpm-5631 ****
    2017-09-23 20:12:25,   4289,      29.33,         439,       0.51,      146.23,       14.97,       74.78,    4303,       0
    **** cmm-nginx-php-fpm-5631-static-pm ****
    2017-09-23 20:16:44,   4834,      29.96,         495,       0.48,      161.35,       16.52,       77.54,    4857,       0
    **** cmm-nginx-php-fpm-5631-dynamic-pm ****
    2017-09-23 20:20:50,   5134,      30.10,         528,       0.45,      170.56,       17.54,       77.22,    5173,       0
    **** cmm-nginx-php-fpm-5631-dynamic-pm-maxchild40-maxspare36 ****
    2017-09-23 20:24:45,   3581,      29.85,         370,       0.60,      119.97,       12.40,       72.45,    3633,       0
    **** cmm-nginx-php-fpm-5631-dynamic-pm-maxchild40-maxspare36-run2 ****
    2017-09-23 20:29:35,   4804,      29.67,         497,       0.37,      161.91,       16.75,       59.66,    4868,       0
    

    Seems to have lowered performance though testing is on my laptop via virtualbox with 4 cpu threads on a i7 3635QM 4C/8T Samsung ATIV Book 8 so virtualisation can be a factor so proper tests should be done on a VPS or dedicated which isn't busy with other tasks :)

    Next change Nginx Unit PHP from 10 to 20 workers via Nginx Unit API
    Code (Text):
    curl -X PUT -d '20' --unix-socket /opt/unit/control.unit.sock http://localhost/applications/php56domaincom/workers
    {
            "success": "Reconfiguration done."
    }
    

    Code (Text):
     curl --unix-socket /opt/unit/control.unit.sock http://localhost/applications/php56domaincom
    {
            "type": "php",
            "workers": 20,
            "root": "/home/nginx/domains/domain.com/public",
            "user": "nginx",
            "group": "nginx",
            "index": "index.php"
    }
    

    Nginx Unit 0.1 + PHP 5.6.31 settings running on port 8300 with 20 workers but not all requests completed only 98.64% completed so too many workers for a 4 cpu thread virtualbox system to handle. So interesting to see how much native PHP-FPM can be tuned to scale and still retain 100% request completion rate compared to Nginx Unit's PHP build, though at 10 workers already faster so is there any need to push to 20 workers ?
    Code (Text):
    siege -b -c100 -t30s http://domain.com:8300/index.php -m nginx-unit-php5631-20-workers
    
    Transactions:                   6913 hits
    Availability:                  98.64 %
    Elapsed time:                  29.89 secs
    Data transferred:             683.65 MB
    Response time:                  0.41 secs
    Transaction rate:             231.28 trans/sec
    Throughput:                    22.87 MB/sec
    Concurrency:                   94.66
    Successful transactions:        6914
    Failed transactions:              95
    Longest transaction:            3.93
    Shortest transaction:           0.01
    


    All tests
    Code (Text):
    head -n1 /usr/local/var/log/siege.log; tail -14 /usr/local/var/log/siege.log                              
          Date & Time,  Trans,  Elap Time,  Data Trans,  Resp Time,  Trans Rate,  Throughput,  Concurrent,    OKAY,   Failed
    **** nginx-unit-php5631 ****
    2017-09-23 20:10:42,   8279,      29.26,         818,       0.35,      282.95,       27.96,       97.74,    8281,       0
    **** cmm-nginx-php-fpm-5631 ****
    2017-09-23 20:12:25,   4289,      29.33,         439,       0.51,      146.23,       14.97,       74.78,    4303,       0
    **** cmm-nginx-php-fpm-5631-static-pm ****
    2017-09-23 20:16:44,   4834,      29.96,         495,       0.48,      161.35,       16.52,       77.54,    4857,       0
    **** cmm-nginx-php-fpm-5631-dynamic-pm ****
    2017-09-23 20:20:50,   5134,      30.10,         528,       0.45,      170.56,       17.54,       77.22,    5173,       0
    **** cmm-nginx-php-fpm-5631-dynamic-pm-maxchild40-maxspare36 ****
    2017-09-23 20:24:45,   3581,      29.85,         370,       0.60,      119.97,       12.40,       72.45,    3633,       0
    **** cmm-nginx-php-fpm-5631-dynamic-pm-maxchild40-maxspare36-run2 ****
    2017-09-23 20:29:35,   4804,      29.67,         497,       0.37,      161.91,       16.75,       59.66,    4868,       0
    **** nginx-unit-php5631-20-workers ****
    2017-09-23 20:39:22,   6913,      29.89,         683,       0.41,      231.28,       22.85,       94.66,    6914,      95
    

    The above was testing Nginx Unit PHP directly via port 8300. But in practice you're probably have Nginx as a reverse proxy/load balancing config outlined at http://unit.nginx.org/docs-integration-with-nginx.html so next tests would be with Centmin Mod Nginx in front so in Centmin Mod Nginx vhost comment out php.conf include which servers PHP-FPM and set proxy to Nginx Unit PHP upstream on port 8300
    Code (Text):
    upstream unit_backend {
          server 127.0.0.1:8300;
    }
    

    Code (Text):
      #include /usr/local/nginx/conf/php.conf;
    
        location ~ \.php$ {
            proxy_pass http://unit_backend;
            proxy_set_header Host $host;
        }
    

    left at Nginx Unit with PHP 20 workers seemed to have 100% completion but lower performance so seems Nginx itself is one to slow things down in both PHP-FPM native config and Nginx Unit PHP configurations
    Code (Text):
    siege -b -c100 -t30s http://domain.com:8080/index.php -m nginxproxy-unit-php5631-20-workers
    Transactions:                   5182 hits
    Availability:                 100.00 %
    Elapsed time:                  29.68 secs
    Data transferred:             514.63 MB
    Response time:                  0.48 secs
    Transaction rate:             174.60 trans/sec
    Throughput:                    17.34 MB/sec
    Concurrency:                   84.57
    Successful transactions:        5205
    Failed transactions:               0
    Longest transaction:            2.14
    Shortest transaction:           0.01
    

    with Nginx Unit PHP 10 workers
    Code (Text):
    siege -b -c100 -t30s http://domain.com:8080/index.php -m nginxproxy-unit-php5631-10-workers
    Transactions:                   4318 hits
    Availability:                 100.00 %
    Elapsed time:                  30.03 secs
    Data transferred:             427.03 MB
    Response time:                  0.60 secs
    Transaction rate:             143.79 trans/sec
    Throughput:                    14.22 MB/sec
    Concurrency:                   85.98
    Successful transactions:        4319
    Failed transactions:               0
    Longest transaction:            3.07
    Shortest transaction:           0.02
    

    with Nginx Unit PHP increased from 20 workers to 30 workers
    Code (Text):
    siege -b -c100 -t30s http://domain.com:8080/index.php -m nginxproxy-unit-php5631-30-workers
    Transactions:                   3920 hits
    Availability:                 100.00 %
    Elapsed time:                  29.79 secs
    Data transferred:             387.58 MB
    Response time:                  0.74 secs
    Transaction rate:             131.59 trans/sec
    Throughput:                    13.01 MB/sec
    Concurrency:                   97.14
    Successful transactions:        3920
    Failed transactions:               0
    Longest transaction:            2.00
    Shortest transaction:           0.01
    

    Code (Text):
    head -n1 /usr/local/var/log/siege.log; tail -18 /usr/local/var/log/siege.log
          Date & Time,  Trans,  Elap Time,  Data Trans,  Resp Time,  Trans Rate,  Throughput,  Concurrent,    OKAY,   Failed
    **** nginx-unit-php5631 ****
    2017-09-23 20:10:42,   8279,      29.26,         818,       0.35,      282.95,       27.96,       97.74,    8281,       0
    **** cmm-nginx-php-fpm-5631 ****
    2017-09-23 20:12:25,   4289,      29.33,         439,       0.51,      146.23,       14.97,       74.78,    4303,       0
    **** cmm-nginx-php-fpm-5631-static-pm ****
    2017-09-23 20:16:44,   4834,      29.96,         495,       0.48,      161.35,       16.52,       77.54,    4857,       0
    **** cmm-nginx-php-fpm-5631-dynamic-pm ****
    2017-09-23 20:20:50,   5134,      30.10,         528,       0.45,      170.56,       17.54,       77.22,    5173,       0
    **** cmm-nginx-php-fpm-5631-dynamic-pm-maxchild40-maxspare36 ****
    2017-09-23 20:24:45,   3581,      29.85,         370,       0.60,      119.97,       12.40,       72.45,    3633,       0
    **** cmm-nginx-php-fpm-5631-dynamic-pm-maxchild40-maxspare36-run2 ****
    2017-09-23 20:29:35,   4804,      29.67,         497,       0.37,      161.91,       16.75,       59.66,    4868,       0
    **** nginx-unit-php5631-20-workers ****
    2017-09-23 20:39:22,   6913,      29.89,         683,       0.41,      231.28,       22.85,       94.66,    6914,      95
    **** nginxproxy-unit-php5631-20-workers ****
    2017-09-23 20:49:26,   5182,      29.68,         514,       0.48,      174.60,       17.32,       84.57,    5205,       0
    **** nginxproxy-unit-php5631-10-workers ****
    2017-09-23 20:55:08,   4318,      30.03,         427,       0.60,      143.79,       14.22,       85.98,    4319,       0
    **** nginxproxy-unit-php5631-30-workers ****
    2017-09-23 20:58:20,   3920,      29.79,         387,       0.74,      131.59,       12.99,       97.14,    3920,       0
    

    Remember these tests don't measure cpu and memory usage yet.
     
    Last edited: Sep 24, 2017
  11. eva2000

    eva2000 Administrator Staff Member

    49,875
    11,487
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,839
    Local Time:
    1:34 PM
    Nginx 1.21.x
    MariaDB 10.x
    Also note configuration tuning for Nginx Unit PHP isn't available yet according to https://github.com/nginx/unit/issues/6#issuecomment-328930787
    But Nginx Unit is definitely interesting and something I will look at integrating into Centmin Mod as I can easily generate the per Nginx vhost domain's Nginx Unit PHP application at centmin.sh menu option 2, 22 or nv command vhost generation stage and configure Nginx Unit PHP at php compile stage in centmin.sh menu option 5 :)
     
  12. eva2000

    eva2000 Administrator Staff Member

    49,875
    11,487
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,839
    Local Time:
    1:34 PM
    Nginx 1.21.x
    MariaDB 10.x
    FYI, Centmin Mod 123.09beta01 branch added and enabled a new PHP setting for PHPEMBED='y' to enable PHP Embed SAPI library support which is a requirement for Nginx Unit so a centmin.sh menu option 5 PHP compile would be required after updating 123.09beta01 on your server via centmin.sh menu option 23 submenu option 2 https://community.centminmod.com/threads/12924/.
     
  13. nfn

    nfn New Member

    29
    0
    1
    Jun 28, 2015
    Ratings:
    +8
    Local Time:
    4:34 AM
    Unit doesn't have a permanent configuration.
    I've added ExecStartPost=/etc/unit/unit.restoreconfig.sh to the unitd.service so we can have the configuration loaded on start/restart.
    Could be a better way, but works!

    Code:
    #!/bin/sh
    #
    # Legacy action script for "service unitd restoreconfig"
    
    CONFIG=/etc/unit/config
    
    if [ -n "$1" ] ; then
        CONFIG=$1
    fi
    
    if [ ! -e ${CONFIG} ]; then
        echo "Could not find ${CONFIG} for restoring" >&2
        exit 1
    fi
    
    echo "Restoring configuration from ${CONFIG}..."
    
    curl -sS -X PUT -d @${CONFIG} --unix-socket /var/run/control.unit.sock localhost
    
    if [ $? -ne 0 ]; then
        echo "Restoring failed!" >&2
        exit 1
    fi
    
    exit 0
    This script is part of the official nginx unit rpm.
     
  14. eva2000

    eva2000 Administrator Staff Member

    49,875
    11,487
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,839
    Local Time:
    1:34 PM
    Nginx 1.21.x
    MariaDB 10.x
    Actually Nginx Unit has been updated to save config states on restarts. When you configure Nginx Unit pass the --state=state value. Update, though it doesn't save multiple json configs, you need to that separate or merge into one json file https://github.com/nginx/unit/issues/48
    Code (Text):
    ./configure --prefix=/opt/unit --pid=/run/unitd.pid --log=/var/log/unitd.log --modules=modules --user=nginx --group=nginx --state=state
    

    Then manually create the state directory in Nginx Unit install (prefix set) directory so when you restart Nginx Unit service a state/conf.json file is dump/saved for reloading on restart
    Code (Text):
    ls -lah state/
    total 4.0K
    drwxr-xr-x 2 root root  22 Sep 23 10:28 .
    drwxr-xr-x 6 root root  78 Sep 23 10:28 ..
    -rw------- 1 root root 217 Sep 23 10:28 conf.json
    

    Code (Text):
    cat state/conf.json
    {"listeners":{"*:8300":{"application":"php56domaincom"}},"applications":{"php56domaincom":{"type":"php","workers":10,"root":"/home/nginx/domains/domain.com/public","user":"nginx","group":"nginx","index":"index.php"}}}
    

    Using CentOS 7 systemd unit.service file manually created as I am not using Nginx Unit provided RPM but source compiled Nginx Unit on Centmin Mod 123.09beta01
    Code (Text):
    [Unit]
    Description=NGINX Unit
    Wants=network-online.target
    After=syslog.target network-online.target
    
    [Service]
    Type=forking
    PIDFile=/run/unitd.pid
    ExecStart=/opt/unit/sbin/unitd
    ExecReload=/bin/kill -HUP $MAINPID
    
    [Install]
    WantedBy=multi-user.target
    
     
  15. eva2000

    eva2000 Administrator Staff Member

    49,875
    11,487
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,839
    Local Time:
    1:34 PM
    Nginx 1.21.x
    MariaDB 10.x
    Last edited: Sep 24, 2017
  16. eva2000

    eva2000 Administrator Staff Member

    49,875
    11,487
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,839
    Local Time:
    1:34 PM
    Nginx 1.21.x
    MariaDB 10.x
    System limits can affect benchmark and general performance and on CentOS 7.4, Centmin Mod LEMP stack installs automatically tune and optimise system limits. For Centmin Mod Nginx's nginx user the max open file descriptor limits are raised to generous levels ~260000 with 7272 max processes
    Code (Text):
    root      4610  0.0  1.2 115564 23600 ?        Ss   00:54   0:00 nginx: master process /usr/local/sbin/nginx -c /usr/local/nginx/con
    nginx     4611  0.1  2.4 144236 45472 ?        S<   00:54   0:00  \_ nginx: worker process
    nginx     4612  0.1  2.3 144236 45044 ?        S<   00:54   0:00  \_ nginx: worker process
    

    for process id = 4611 nginx process limits
    Code (Text):
    cat /proc/4611/limits
    Limit                     Soft Limit           Hard Limit           Units
    Max cpu time              unlimited            unlimited            seconds
    Max file size             unlimited            unlimited            bytes
    Max data size             unlimited            unlimited            bytes
    Max stack size            8388608              unlimited            bytes
    Max core file size        0                    unlimited            bytes
    Max resident set          unlimited            unlimited            bytes
    Max processes             7272                 7272                 processes
    Max open files            260000               260000               files
    Max locked memory         65536                65536                bytes
    Max address space         unlimited            unlimited            bytes
    Max file locks            unlimited            unlimited            locks
    Max pending signals       7272                 7272                 signals
    Max msgqueue size         819200               819200               bytes
    Max nice priority         0                    0               
    Max realtime priority     0                    0               
    Max realtime timeout      unlimited            unlimited            us
    

    I assumed it was the same for Nginx Unit spawned nginx processes but it wasn't the case as Nginx server itself set those limits within nginx.conf. So Nginx Unit spawned nginx processes had lower limits inherited from root user with soft/hard limits for max open files at 1024/4096
    Code (Text):
    root      4018  0.0  0.0  16428   516 ?        Ss   00:35   0:00 unit: main [/opt/unit/sbin/unitd]
    nginx     4039  0.0  0.0  26672   264 ?        S    00:35   0:00  \_ unit: controller
    nginx     4241  0.0  0.0 1165196   40 ?        S    00:36   0:00  \_ unit: "php71domaincom" application
    

    for process id = 4039
    Code (Text):
    cat /proc/4039/limits
    Limit                     Soft Limit           Hard Limit           Units
    Max cpu time              unlimited            unlimited            seconds
    Max file size             unlimited            unlimited            bytes
    Max data size             unlimited            unlimited            bytes
    Max stack size            8388608              unlimited            bytes
    Max core file size        0                    unlimited            bytes
    Max resident set          unlimited            unlimited            bytes
    Max processes             7272                 7272                 processes
    Max open files            1024                 4096                 files
    Max locked memory         65536                65536                bytes
    Max address space         unlimited            unlimited            bytes
    Max file locks            unlimited            unlimited            locks
    Max pending signals       7272                 7272                 signals
    Max msgqueue size         819200               819200               bytes
    Max nice priority         0                    0             
    Max realtime priority     0                    0             
    Max realtime timeout      unlimited            unlimited            us
    

    for process id = 4242
    Code (Text):
    cat /proc/4241/limits
    Limit                     Soft Limit           Hard Limit           Units
    Max cpu time              unlimited            unlimited            seconds
    Max file size             unlimited            unlimited            bytes
    Max data size             unlimited            unlimited            bytes
    Max stack size            8388608              unlimited            bytes
    Max core file size        0                    unlimited            bytes
    Max resident set          unlimited            unlimited            bytes
    Max processes             7272                 7272                 processes
    Max open files            1024                 4096                 files
    Max locked memory         65536                65536                bytes
    Max address space         unlimited            unlimited            bytes
    Max file locks            unlimited            unlimited            locks
    Max pending signals       7272                 7272                 signals
    Max msgqueue size         819200               819200               bytes
    Max nice priority         0                    0             
    Max realtime priority     0                    0             
    Max realtime timeout      unlimited            unlimited            us
    

    For benchmarking and performance for Nginx Unit processes, make sure unitd systemd service has raised max open file descriptor limits. Here I raised max open files and max processes to 262144 and 16383 respectively. For Centmin Mod's integration of Nginx Unit, I will make sure that unitd systemd service has more optimised settings for this.
    Code (Text):
    mkdir -p /etc/systemd/system/unitd.service.d
    echo -en "[Service]\nLimitNOFILE=262144\nLimitNPROC=16384\n" > /etc/systemd/system/unitd.service.d/limit.conf
    systemctl daemon-reload
    systemctl restart unitd
    

    Code (Text):
    root      4559  0.0  0.0  16032   800 ?        Ss   00:54   0:00 unit: main [/opt/unit/sbin/unitd]
    nginx     4578  0.0  0.0  26276   720 ?        S    00:54   0:00  \_ unit: controller
    nginx     4579  0.0  0.0 341832   912 ?        Sl   00:54   0:00  \_ unit: router
    nginx     4642  5.2  2.7 1175440 52152 ?       S    00:57   0:00  \_ unit: "php71domaincom" application
    

    for process id = 4578
    Code (Text):
    cat /proc/4578/limits
    Limit                     Soft Limit           Hard Limit           Units
    Max cpu time              unlimited            unlimited            seconds
    Max file size             unlimited            unlimited            bytes
    Max data size             unlimited            unlimited            bytes
    Max stack size            8388608              unlimited            bytes
    Max core file size        0                    unlimited            bytes
    Max resident set          unlimited            unlimited            bytes
    Max processes             16384                16384                processes
    Max open files            262144               262144               files
    Max locked memory         65536                65536                bytes
    Max address space         unlimited            unlimited            bytes
    Max file locks            unlimited            unlimited            locks
    Max pending signals       7272                 7272                 signals
    Max msgqueue size         819200               819200               bytes
    Max nice priority         0                    0               
    Max realtime priority     0                    0               
    Max realtime timeout      unlimited            unlimited            us   
    

    for process id = 4579
    Code (Text):
    cat /proc/4579/limits
    Limit                     Soft Limit           Hard Limit           Units
    Max cpu time              unlimited            unlimited            seconds
    Max file size             unlimited            unlimited            bytes
    Max data size             unlimited            unlimited            bytes
    Max stack size            8388608              unlimited            bytes
    Max core file size        0                    unlimited            bytes
    Max resident set          unlimited            unlimited            bytes
    Max processes             16384                16384                processes
    Max open files            262144               262144               files
    Max locked memory         65536                65536                bytes
    Max address space         unlimited            unlimited            bytes
    Max file locks            unlimited            unlimited            locks
    Max pending signals       7272                 7272                 signals
    Max msgqueue size         819200               819200               bytes
    Max nice priority         0                    0               
    Max realtime priority     0                    0               
    Max realtime timeout      unlimited            unlimited            us
    

    for process id = 4642
    Code (Text):
    cat /proc/4642/limits
    Limit                     Soft Limit           Hard Limit           Units
    Max cpu time              unlimited            unlimited            seconds
    Max file size             unlimited            unlimited            bytes
    Max data size             unlimited            unlimited            bytes
    Max stack size            8388608              unlimited            bytes
    Max core file size        0                    unlimited            bytes
    Max resident set          unlimited            unlimited            bytes
    Max processes             16384                16384                processes
    Max open files            262144               262144               files
    Max locked memory         65536                65536                bytes
    Max address space         unlimited            unlimited            bytes
    Max file locks            unlimited            unlimited            locks
    Max pending signals       7272                 7272                 signals
    Max msgqueue size         819200               819200               bytes
    Max nice priority         0                    0               
    Max realtime priority     0                    0               
    Max realtime timeout      unlimited            unlimited            us
    

    This probably explained why siege benchmark tests above for Nginx Unit PHP has some incomplete requests as Unit spawned PHP workers under nginx user ran out of file descriptors ?
     
  17. eva2000

    eva2000 Administrator Staff Member

    49,875
    11,487
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,839
    Local Time:
    1:34 PM
    Nginx 1.21.x
    MariaDB 10.x
    Installing Nginx Unit on Centmin Mod 123.09beta01 with multiple PHP 5.6, 7.0, 7.1, 7.2 and Python versions 2.7, 3.4, 3.5 and 3.6 and Go 1.9
    Code (Text):
    ls -lah /opt/unit/modules
    total 900K
    drwxr-xr-x 2 root root 4.0K Sep 28 04:02 .
    drwxr-xr-x 5 root root   67 Sep 28 04:02 ..
    -rwxr-xr-x 1 root root 110K Sep 28 04:02 iuspython34.unit.so
    -rwxr-xr-x 1 root root 110K Sep 28 04:02 iuspython35.unit.so
    -rwxr-xr-x 1 root root 111K Sep 28 04:02 iuspython36.unit.so
    -rwxr-xr-x 1 root root  89K Sep 28 04:02 php5.6.31.unit.so
    -rwxr-xr-x 1 root root 104K Sep 28 04:02 python.unit.so
    -rwxr-xr-x 1 root root  89K Sep 28 04:02 remiphp56.unit.so
    -rwxr-xr-x 1 root root  88K Sep 28 04:02 remiphp70.unit.so
    -rwxr-xr-x 1 root root  89K Sep 28 04:02 remiphp71.unit.so
    -rwxr-xr-x 1 root root  90K Sep 28 04:02 remiphp72.unit.so
    

    Code (Text):
    tail -100 /var/log/unitd.log
    2017/09/28 04:02:31 [info] 8563#8563 discovery started
    2017/09/28 04:02:31 [notice] 8563#8563 module: python 3.4.7 "/opt/unit/modules/iuspython34.unit.so"
    2017/09/28 04:02:31 [notice] 8563#8563 module: python 3.5.4 "/opt/unit/modules/iuspython35.unit.so"
    2017/09/28 04:02:31 [notice] 8563#8563 module: python 3.6.2 "/opt/unit/modules/iuspython36.unit.so"
    2017/09/28 04:02:31 [notice] 8563#8563 module: php 5.6.31 "/opt/unit/modules/php5.6.31.unit.so"
    2017/09/28 04:02:31 [notice] 8563#8563 module: python 2.7.5 "/opt/unit/modules/python.unit.so"
    2017/09/28 04:02:31 [notice] 8563#8563 module: php 5.6.31 "/opt/unit/modules/remiphp56.unit.so"
    2017/09/28 04:02:31 [notice] 8563#8563 ignoring /opt/unit/modules/remiphp56.unit.so module with the same application language version php 5.6.31 as in /opt/unit/modules/php5.6.31.unit.so
    2017/09/28 04:02:31 [notice] 8563#8563 module: php 7.0.24 "/opt/unit/modules/remiphp70.unit.so"
    2017/09/28 04:02:31 [notice] 8563#8563 module: php 7.1.10 "/opt/unit/modules/remiphp71.unit.so"
    2017/09/28 04:02:31 [notice] 8563#8563 module: php 7.2.0RC3 "/opt/unit/modules/remiphp72.unit.so"
    2017/09/28 04:02:31 [info] 8566#8566 controller started
    2017/09/28 04:02:31 [info] 8567#8567 router started
    
     
  18. eva2000

    eva2000 Administrator Staff Member

    49,875
    11,487
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,839
    Local Time:
    1:34 PM
    Nginx 1.21.x
    MariaDB 10.x
    Nginx Unit development and news update NGINX Unit, Three Months In: Progress and Next Steps - NGINX

     
  19. eva2000

    eva2000 Administrator Staff Member

    49,875
    11,487
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,839
    Local Time:
    1:34 PM
    Nginx 1.21.x
    MariaDB 10.x
    Quick revisit of Nginx Unit Application server v0.8 as v1.0 is nearing release Updating the NGINX Application Platform | NGINX

    Docs

    On Centmin Mod 123.09beta01 with CentOS 7.4 with Nginx Unit 0.8 built with GCC 7.2.1
    Code (Text):
    /opt/unit/sbin/unitd --version
    unit version: 0.8
    configured as ./configure --prefix=/opt/unit --pid=/run/unitd.pid --log=/var/log/unitd.log --modules=modules --user=nginx --group=nginx --state=state --cc-opt='-O3 -fstack-protector-strong -fuse-ld=gold -Wimplicit-fallthrough=0 -fcode-hoisting'

    Code (Text):
    systemctl status unitd
    ● unitd.service - NGINX Unit
       Loaded: loaded (/usr/lib/systemd/system/unitd.service; disabled; vendor preset: disabled)
      Drop-In: /etc/systemd/system/unitd.service.d
               └─limit.conf
       Active: active (running) since Tue 2018-04-03 16:59:06 UTC; 13s ago
      Process: 18972 ExecStart=/opt/unit/sbin/unitd (code=exited, status=0/SUCCESS)
     Main PID: 18973 (unitd)
       CGroup: /system.slice/unitd.service
               ├─18973 unit: main [/opt/unit/sbin/unitd]
               ├─18975 unit: controller
               └─18976 unit: router
    
    Apr 03 16:59:06 centos7.localdomain systemd[1]: Starting NGINX Unit...
    Apr 03 16:59:06 centos7.localdomain unitd[18972]: 2018/04/03 16:59:06 [info] 18972#18972 unit started
    Apr 03 16:59:06 centos7.localdomain systemd[1]: Started NGINX Unit.

    Code (Text):
    root     18973  0.0  0.0  16116   620 ?        Ss   16:59   0:00 unit: main [/opt/unit/sbin/unitd]
    nginx    18975  0.0  0.0  16116   424 ?        S    16:59   0:00  \_ unit: controller
    nginx    18976  0.0  0.0  16116   424 ?        S    16:59   0:00  \_ unit: router

    Code (Text):
    ls -lah /opt/unit/
    total 4.0K
    drwxr-xr-x  5 root root   67 Apr  3 16:59 .
    drwxr-xr-x. 7 root root   66 Apr  3 16:57 ..
    srw-------  1 root root    0 Apr  3 16:59 control.unit.sock
    drwxr-xr-x  2 root root 4.0K Apr  3 16:57 modules
    drwxr-xr-x  2 root root   18 Apr  3 16:57 sbin
    drwxr-xr-x  2 root root    6 Apr  3 16:57 state

    Nginx Unit now has added perl, ruby support with existing golang, php and python :)
    Code (Text):
    ls -lah /opt/unit/modules/
    total 804K
    drwxr-xr-x 2 root root 4.0K Apr  3 16:57 .
    drwxr-xr-x 5 root root   67 Apr  3 16:59 ..
    -rwxr-xr-x 1 root root 179K Apr  3 16:57 perl516.unit.so
    -rwxr-xr-x 1 root root 101K Apr  3 16:57 python27.unit.so
    -rwxr-xr-x 1 root root  92K Apr  3 16:57 remiphp5635.unit.so
    -rwxr-xr-x 1 root root  91K Apr  3 16:57 remiphp7029.unit.so
    -rwxr-xr-x 1 root root  93K Apr  3 16:57 remiphp7116.unit.so
    -rwxr-xr-x 1 root root  93K Apr  3 16:57 remiphp724.unit.so
    -rwxr-xr-x 1 root root 137K Apr  3 16:57 ruby251.unit.so

    First application and listener on port 8600 for PHP 7.2.4 embedded server
    Code (Text):
    curl --unix-socket /opt/unit/control.unit.sock http://localhost/
    {
            "listeners": {
                    "*:8600": {
                            "application": "php72domaincom"
                    }
            },
    
            "applications": {
                    "php72domaincom": {
                            "type": "php 7.2.4",
                            "processes": 20,
                            "root": "/home/nginx/domains/domain.com/public",
                            "user": "nginx",
                            "group": "nginx",
                            "index": "index.php"
                    }
            }
    }

    Nginx Unit log on restart
    Code (Text):
    tail -100 /var/log/unitd.log                                                                                   
    
    2018/04/03 17:13:36 [info] 19669#19669 discovery started
    2018/04/03 17:13:36 [notice] 19669#19669 module: perl 5.16.3 "/opt/unit/modules/perl516.unit.so"
    2018/04/03 17:13:36 [notice] 19669#19669 module: python 2.7.5 "/opt/unit/modules/python27.unit.so"
    2018/04/03 17:13:36 [notice] 19669#19669 module: php 5.6.35 "/opt/unit/modules/remiphp5635.unit.so"
    2018/04/03 17:13:36 [notice] 19669#19669 module: php 7.0.29 "/opt/unit/modules/remiphp7029.unit.so"
    2018/04/03 17:13:36 [notice] 19669#19669 module: php 7.1.16 "/opt/unit/modules/remiphp7116.unit.so"
    2018/04/03 17:13:36 [notice] 19669#19669 module: php 7.2.4 "/opt/unit/modules/remiphp724.unit.so"
    2018/04/03 17:13:36 [notice] 19669#19669 module: ruby 2.5.0 "/opt/unit/modules/ruby251.unit.so"
    2018/04/03 17:13:37 [info] 19670#19670 controller started
    2018/04/03 17:13:37 [notice] 19668#19668 process 19669 exited with code 0
    2018/04/03 17:13:37 [info] 19671#19671 router started
    2018/04/03 17:13:37 [info] 19672#19672 "php72domaincom" application started
    2018/04/03 17:13:37 [info] 19672#19672 (non ABS_MODE) php root: "/home/nginx/domains/domain.com/public"
    2018/04/03 17:13:37 [info] 19673#19673 "php72domaincom" application started
    2018/04/03 17:13:37 [info] 19673#19673 (non ABS_MODE) php root: "/home/nginx/domains/domain.com/public"
    2018/04/03 17:13:37 [info] 19674#19674 "php72domaincom" application started
    2018/04/03 17:13:37 [info] 19674#19674 (non ABS_MODE) php root: "/home/nginx/domains/domain.com/public"
    2018/04/03 17:13:37 [info] 19675#19675 "php72domaincom" application started
    2018/04/03 17:13:37 [info] 19675#19675 (non ABS_MODE) php root: "/home/nginx/domains/domain.com/public"
    2018/04/03 17:13:38 [info] 19676#19676 "php72domaincom" application started
    2018/04/03 17:13:38 [info] 19676#19676 (non ABS_MODE) php root: "/home/nginx/domains/domain.com/public"
    2018/04/03 17:13:38 [info] 19677#19677 "php72domaincom" application started
    2018/04/03 17:13:38 [info] 19677#19677 (non ABS_MODE) php root: "/home/nginx/domains/domain.com/public"
    2018/04/03 17:13:38 [info] 19678#19678 "php72domaincom" application started
    2018/04/03 17:13:38 [info] 19678#19678 (non ABS_MODE) php root: "/home/nginx/domains/domain.com/public"
    2018/04/03 17:13:38 [info] 19679#19679 "php72domaincom" application started
    2018/04/03 17:13:38 [info] 19679#19679 (non ABS_MODE) php root: "/home/nginx/domains/domain.com/public"
    2018/04/03 17:13:39 [info] 19680#19680 "php72domaincom" application started
    2018/04/03 17:13:39 [info] 19680#19680 (non ABS_MODE) php root: "/home/nginx/domains/domain.com/public"
    2018/04/03 17:13:39 [info] 19681#19681 "php72domaincom" application started
    2018/04/03 17:13:39 [info] 19681#19681 (non ABS_MODE) php root: "/home/nginx/domains/domain.com/public"