Unit 0.6 Beta Release Available Now

Unit 0.6 Beta Release Available Now

On February 9th, 2018, we released the sixth beta version of NGINX Unit, our new dynamic web and application server. In this blog post, we discuss the latest changes in detail.

We made some changes to the configuration API, so please review this article before upgrading your existing Unit installation.

NGINX Unit is under active development. It’s likely that at the time you read this blog post, even more recent releases will be available. Check https://unit.nginx.org/CHANGES.txt for details on the latest release.

Highlights of the changes since the Unit 0.3 release:

  • Advanced process management and prefork model
  • Added support for Perl
  • Official Docker containers (featured on Docker Hub)
  • Packages for more operating systems: Amazon Linux

With the addition of Perl support, we are now able to run applications like Bugzilla, a popular bug-tracking system written in Perl.

Advanced Process Management

Note: the workers parameter of application objects is now removed in favor of several more granular features.

In previous versions of Unit, the only method of limiting your worker count was by providing a workers parameter to the application object. Now, you can manage your application more granularly through the new processes {} object.

Below, we describe the available options.

Setting the maximum number of workers with the max parameter

When application load rises, Unit creates more application processes. However, it will not fork more application processes than defined in the max parameter of the processes {} object. By default, this value is set to 1.

The example below allows up to 10 workers:

{
    "listeners": {
        "*:8090": {
            "application": "myblog"
        }
    },

    "applications": {
        "myblog": {
            "type": "php",
            "root": "/srv/myblog",
            "processes": {
                "max": 10,
            }
        }
    }
}

You can change the parameter without reloading the rest of the configuration by connecting to the API:

curl -X PUT -d 3 --unix-socket /path/to/control.unit.sock http://localhost/applications/myblog/processes/max

Prefork and scaling down unused workers with the spare parameter

When the application starts, Unit will create the number of workers specified in the spare parameter of the processes {} object. When the load is low, and the processes are idle, Unit will scale down to the number specified by the parameter. By default, this parameter is set to 0.

The code in the example below creates 5 application processes immediately, scales up to 10 processes when the load increases, and scales back down to 5 when the load is low:

{
    "listeners": {
        "*:8090": {
            "application": "myblog"
        }
    },

    "myblog": {
        "crossplane": {
            "type": "php",
            "root": "/srv/myblog",
            "processes": {
                "max": 10,
                "spare": 5
            }
        }
    }
}

You can change the parameter without reloading the rest of configuration by connecting to the API:

curl -X PUT -d 3 --unix-socket /path/to/control.unit.sock http://localhost/applications/myblog/processes/spare

The number of spare processes must be lower than, or equal to, the maximum number of processes. Thus, you cannot define spare to a value other than 1 unless you previously define the corresponding max parameter.

The idle_timeout parameter

The idle_timeout parameter is used to configure the time required for Unit to wait before scaling down the unused worker. It is defined in seconds and is set to 15 seconds by default. In the following example, Unit will wait for a worker to be inactive for 20 seconds before terminating it.

{
    "listeners": {
        "*:8090": {
            "application": "myblog"
        }
    },

    "myblog": {
        "crossplane": {
            "type": "php",
            "root": "/srv/myblog",
            "processes": {
                "max": 10,
                "spare": 5,
                "idle_timeout": 20,
            }
        }
    }
}

As with any other parameter, you can change it directly through an API call, and it will not cause a reload event:

curl -X PUT -d 15 --unix-socket /path/to/control.unit.sock http://localhost/applications/myblog/processes/idle_timeout

Basic process management

If you want to use a simpler, static process model, you can set the processes option to an integer value. In that case, Unit will start the specified number of application processes immediately, and will keep them active without scaling up or down.

An application object example would look like this:

        {
            "type": "php",
            "root": "/srv/myblog",
            "processes": 10
        }

PSGI/Perl support

Unit now supports the Perl Server Gateway Interface (PSGI).

Note: PSGI applications are different from Perl CGI applications, which Unit does not support.

If you install packages from our repositories, install the unit-perl package. It’s available for all operating systems that we provide packages for.

If you compile Unit from source, you will need to install developer libraries for Perl before compiling the source. Install the Perl libraries:

  • libperl-dev for Debian/Ubuntu
  • perl-devel and perl-libs for CentOS/RHEL

Note: We tested Unit with various versions of Perl, starting with 5.12. It may work with older versions as well, but we have not tested this.

Your application object would look like this:

        {
            "type": "perl",
            "user": "nobody",
            "working_directory": "/my/bugtracker",
            "script": "app.psgi"
        }

The simple application below collects environment variables and prints them out:

use Data::Dumper;

my $app = sub {
      my $env = shift;
      return [
          '200',
          [ 'Content-Type' => 'text/plain' ],
          [ "Hello from Unit, Perl $^V, environment:nn", Dumper($env) ],
      ];
};

As with the other languages that Unit supports, you can use all the listener features, process management features, and security features the same way with Perl applications as you would with any other app.

Official Docker Containers

Docker containers for Unit are now available here: https://hub.docker.com/r/nginx/unit/

If you look at the list of available tags, you will see multiple versions of the container:
https://hub.docker.com/r/nginx/unit/tags/

Here’s a quick overview:

  • unit-full includes the modules for all supported languages and will also run precompiled Go apps. If you are unsure which languages you will want to use, try this container.
  • unit-minimal does not include modules and interpreters for any languages. However, it is capable of running precompiled Go apps.
  • unit-php is able to run PHP scripts and precompiled Go apps.
  • unit-python is able to run Python scripts and precompiled Go apps.
  • unit-go1.7-dev and unit-go1.8-dev are able to compile Go apps with the appropriate nginx/unit packages for the specified version of Go, as well as run precompiled Go apps.

The :latest tag (used by default) links to the unit-full container.

In the simplest case, to run Unit in Docker, pull and run nginx/unit, then use the API from within the container to configure it.

If more sophisticated configuration is required, you can mount the volumes and have the container socket accessible from the host or from another container, or have the control socket available via a TCP port.

Amazon Linux Support

Unit packages are now available for Amazon Linux. To learn how to install the precompiled packages for Amazon Linux, follow this link:
http://unit.nginx.org/installation/#amazon-linux-packages

Conclusion

With the 0.6 version, Unit is getting close to the functionality, language support, and reliability it will have when we reach general availability (GA) for Unit 1.0, as described in our road map blog post and shown in our demo. Please continue to experiment with Unit and send us your feedback on GitHub.

The post Unit 0.6 Beta Release Available Now appeared first on NGINX.

Source: Unit 0.6 Beta Release Available Now

About KENNETH 19694 Articles
지락문화예술공작단

Be the first to comment

Leave a Reply

Your email address will not be published.


*


이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.