diff options
author | Valery Piashchynski <[email protected]> | 2020-02-26 16:51:18 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-02-26 16:51:18 +0300 |
commit | a2d1bc08a29a4e95020db2d92ae35e6194b6b179 (patch) | |
tree | d8dbf1d8dcac7cc423d5bf5e6bac8b0280a1fa24 | |
parent | f9c4839266ff5c9aa289b2db0dae1e157011ffd3 (diff) |
Add reuse, defer and fast-accept ports
Slightly update CI, add windows and macOS build targets
-rw-r--r-- | .github/workflows/ci-build.yml | 171 | ||||
-rw-r--r-- | go.mod | 1 | ||||
-rw-r--r-- | go.sum | 2 | ||||
-rw-r--r-- | util/network.go | 15 | ||||
-rw-r--r-- | util/network_windows.go | 33 |
5 files changed, 137 insertions, 85 deletions
diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index b0977521..24123525 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -5,99 +5,100 @@ on: [push, pull_request] jobs: build: name: Build (PHP ${{ matrix.php }}, Go ${{ matrix.go }}) - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: php: [7.1, 7.2, 7.3, 7.4] go: [1.12, 1.13] + os: [ubuntu-latest, macOS-latest, windows, latest] env: GO111MODULE: on steps: - - name: Set up Go ${{ matrix.go }} - uses: actions/setup-go@v1 - with: - go-version: ${{ matrix.go }} - - - name: Set up PHP ${{ matrix.php }} - uses: shivammathur/setup-php@v1 - with: - php-version: ${{ matrix.php }} - extensions: dom - coverage: xdebug - - - name: Check out code - uses: actions/checkout@v2 - with: - fetch-depth: 1 - - - name: Show versions - run: php -v && composer -V && go version - - - name: Debug if needed - env: - DEBUG: ${{ secrets.DEBUG }} - run: if [[ "$DEBUG" == "true" ]]; then env && go env; fi - - - name: Syntax check only (lint) - run: find ./src/ -name "*.php" -print0 | xargs -0 -n1 -P8 php -l - - - name: Get Composer Cache Directory # Docs: <https://github.com/actions/cache/blob/master/examples.md#php---composer> - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: Cache dependencies # Docs: <https://github.com/actions/cache/blob/master/examples.md#php---composer> - uses: actions/cache@v1 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-composer- - - - name: Install Composer dependencies - run: composer install --prefer-dist --no-interaction --no-suggest # --prefer-source - - - name: Analyze PHP sources - run: composer analyze - - - name: Install Go dependencies - run: go mod download - - - name: Download binary roadrunner - run: php ./bin/rr get-binary - - - name: Run golang tests - run: | - go test -race -v -coverprofile=lib.txt -covermode=atomic - go test ./util -race -v -coverprofile=util.txt -covermode=atomic - go test ./service -race -v -coverprofile=service.txt -covermode=atomic - go test ./service/env -race -v -coverprofile=env.txt -covermode=atomic - go test ./service/rpc -race -v -coverprofile=rpc.txt -covermode=atomic - go test ./service/http -race -v -coverprofile=http.txt -covermode=atomic - go test ./service/static -race -v -coverprofile=static.txt -covermode=atomic - go test ./service/limit -race -v -coverprofile=limit.txt -covermode=atomic - go test ./service/headers -race -v -coverprofile=headers.txt -covermode=atomic - go test ./service/metrics -race -v -coverprofile=metrics.txt -covermode=atomic - go test ./service/health -race -v -coverprofile=health.txt -covermode=atomic - - - name: Run code coverage - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - run: | - if [[ "$CODECOV_TOKEN" != "" ]]; then - curl https://codecov.io/bash -o codecov-bash - chmod +x codecov-bash - ./codecov-bash -f lib.txt - ./codecov-bash -f util.txt - ./codecov-bash -f service.txt - ./codecov-bash -f env.txt - ./codecov-bash -f rpc.txt - ./codecov-bash -f http.txt - ./codecov-bash -f static.txt - ./codecov-bash -f limit.txt - ./codecov-bash -f headers.txt - ./codecov-bash -f metrics.txt - ./codecov-bash -f health.txt - fi + - name: Set up Go ${{ matrix.go }} + uses: actions/setup-go@v1 + with: + go-version: ${{ matrix.go }} + + - name: Set up PHP ${{ matrix.php }} + uses: shivammathur/setup-php@v1 + with: + php-version: ${{ matrix.php }} + extensions: dom + coverage: xdebug + + - name: Check out code + uses: actions/checkout@v2 + with: + fetch-depth: 1 + + - name: Show versions + run: php -v && composer -V && go version + + - name: Debug if needed + env: + DEBUG: ${{ secrets.DEBUG }} + run: if [[ "$DEBUG" == "true" ]]; then env && go env; fi + + - name: Syntax check only (lint) + run: find ./src/ -name "*.php" -print0 | xargs -0 -n1 -P8 php -l + + - name: Get Composer Cache Directory # Docs: <https://github.com/actions/cache/blob/master/examples.md#php---composer> + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies # Docs: <https://github.com/actions/cache/blob/master/examples.md#php---composer> + uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install Composer dependencies + run: composer install --prefer-dist --no-interaction --no-suggest # --prefer-source + + - name: Analyze PHP sources + run: composer analyze + + - name: Install Go dependencies + run: go mod download + + - name: Download binary roadrunner + run: php ./bin/rr get-binary + + - name: Run golang tests + run: | + go test -race -v -coverprofile=lib.txt -covermode=atomic + go test ./util -race -v -coverprofile=util.txt -covermode=atomic + go test ./service -race -v -coverprofile=service.txt -covermode=atomic + go test ./service/env -race -v -coverprofile=env.txt -covermode=atomic + go test ./service/rpc -race -v -coverprofile=rpc.txt -covermode=atomic + go test ./service/http -race -v -coverprofile=http.txt -covermode=atomic + go test ./service/static -race -v -coverprofile=static.txt -covermode=atomic + go test ./service/limit -race -v -coverprofile=limit.txt -covermode=atomic + go test ./service/headers -race -v -coverprofile=headers.txt -covermode=atomic + go test ./service/metrics -race -v -coverprofile=metrics.txt -covermode=atomic + go test ./service/health -race -v -coverprofile=health.txt -covermode=atomic + + - name: Run code coverage + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + run: | + if [[ "$CODECOV_TOKEN" != "" ]]; then + curl https://codecov.io/bash -o codecov-bash + chmod +x codecov-bash + ./codecov-bash -f lib.txt + ./codecov-bash -f util.txt + ./codecov-bash -f service.txt + ./codecov-bash -f env.txt + ./codecov-bash -f rpc.txt + ./codecov-bash -f http.txt + ./codecov-bash -f static.txt + ./codecov-bash -f limit.txt + ./codecov-bash -f headers.txt + ./codecov-bash -f metrics.txt + ./codecov-bash -f health.txt + fi golangci-check: name: runner / golangci-lint @@ -19,6 +19,7 @@ require ( github.com/spf13/viper v1.6.2 github.com/spiral/goridge v2.1.4+incompatible github.com/stretchr/testify v1.5.1 + github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a github.com/yookoala/gofast v0.4.0 golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 ) @@ -194,6 +194,8 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a h1:0R4NLDRDZX6JcmhJgXi5E4b8Wg84ihbmUKp/GvSPEzc= +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yookoala/gofast v0.4.0 h1:dLBjghcsbbZNOEHN8N1X/gh9S6srmJed4WQfG7DlKwo= diff --git a/util/network.go b/util/network.go index b9066de7..54d29519 100644 --- a/util/network.go +++ b/util/network.go @@ -1,8 +1,11 @@ +// +build linux + package util import ( "errors" "fmt" + "github.com/valyala/tcplisten" "net" "os" "strings" @@ -27,6 +30,18 @@ func CreateListener(address string) (net.Listener, error) { } } + cfg := tcplisten.Config{ + ReusePort: true, + DeferAccept: true, + FastOpen: true, + Backlog: 0, + } + + // tcp4 is currently supported + if dsn[0] == "tcp" { + return cfg.NewListener("tcp4", dsn[1]) + } + return net.Listen(dsn[0], dsn[1]) } diff --git a/util/network_windows.go b/util/network_windows.go new file mode 100644 index 00000000..e5bc67c8 --- /dev/null +++ b/util/network_windows.go @@ -0,0 +1,33 @@ +// +build windows + +package util + +import ( + "errors" + "fmt" + "net" + "os" + "strings" + "syscall" +) + +// CreateListener crates socket listener based on DSN definition. +func CreateListener(address string) (net.Listener, error) { + dsn := strings.Split(address, "://") + if len(dsn) != 2 { + return nil, errors.New("invalid DSN (tcp://:6001, unix://file.sock)") + } + + if dsn[0] != "unix" && dsn[0] != "tcp" { + return nil, errors.New("invalid Protocol (tcp://:6001, unix://file.sock)") + } + + if dsn[0] == "unix" && fileExists(dsn[1]) { + err := syscall.Unlink(dsn[1]) + if err != nil { + return nil, fmt.Errorf("error during the unlink syscall: error %v", err) + } + } + + return net.Listen(dsn[0], dsn[1]) +}
\ No newline at end of file |