diff --git a/bin/ngxway b/bin/ngxway index 57fd6c4..9034ff7 100755 --- a/bin/ngxway +++ b/bin/ngxway @@ -42,26 +42,33 @@ function start(){ mkdir -p $localVolumeLogsDir && chmod -R 777 $localVolumeLogsDir # Adjust system parameters and run container. - docker run --ulimit nofile=1048576:1048576 \ - --sysctl net.ipv4.ip_local_port_range="1024 65535" \ - --sysctl net.core.somaxconn="262155" \ - --sysctl net.ipv4.tcp_tw_reuse="1" \ - --sysctl net.ipv4.tcp_max_tw_buckets="700" \ - --sysctl net.ipv4.tcp_syncookies="0" \ - --cpus=8 \ - --name ngxwayContainer -d -p $ngxwayAddr:8090 -p 8000:8000 -v $localVolumeLogsDir:/dist/logs/ ngxway - if [ $? -ne 0 ]; then - printError "error: failed to run" - exit 1 + if [ $dockerNetwork == "bridge" ]; then + docker run --ulimit nofile=$softNoFile:$hardNoFile \ + --sysctl net.ipv4.ip_local_port_range="$ipLocalPortRange" \ + --sysctl net.core.somaxconn="$soMaxConn" \ + --sysctl net.ipv4.tcp_tw_reuse="$tcpTWReuse" \ + --sysctl net.ipv4.tcp_max_tw_buckets="$tcpMaxTWBuckets" \ + --sysctl net.ipv4.tcp_syncookies="$tcpSyncookies" \ + --cpus=$maxNCPU \ + --name ngxwayContainer -d -p $ngxwayAddr:8090 -p 8000:8000 -v $localVolumeLogsDir:/dist/logs/ ngxway + if [ $? -ne 0 ]; then + printError "error: failed to run" + exit 1 + fi + elif [ $dockerNetwork == "host" ]; then + docker run --ulimit nofile=$softNoFile:$hardNoFile \ + --cpus=$maxNCPU \ + --name ngxwayContainer -d --net=host -v $localVolumeLogsDir:/dist/logs/ ngxway + if [ $? -ne 0 ]; then + printError "error: failed to run" + exit 1 + fi fi # Exec command: start the go server. if [ $env == "dev" ]; then printInfo "DEV ONLY START" - # install httpd-tools to use ab test, - docker exec -it ngxwayContainer /bin/bash -c 'yum install -y httpd-tools' - # build go server docker exec -it ngxwayContainer /bin/bash -c 'cd /dist/example/goserver/ && bash build.sh && cd /' if [ $? -ne 0 ]; then diff --git a/example/goserver/build.sh b/example/goserver/build.sh index ccdd537..7cc5c9a 100644 --- a/example/goserver/build.sh +++ b/example/goserver/build.sh @@ -1,7 +1,10 @@ -wget https://dl.google.com/go/go1.15.linux-amd64.tar.gz -tar -C /usr/local -xzf go1.15.linux-amd64.tar.gz +# Check go is installed. +if ! command -v go &> /dev/null; then + wget https://dl.google.com/go/go1.15.linux-amd64.tar.gz + tar -C /usr/local -xzf go1.15.linux-amd64.tar.gz + rm -f go1.15.linux-amd64.tar.gz +fi + export PATH=$PATH:/usr/local/go/bin go env -w GO111MODULE=on -rm -f go1.15.linux-amd64.tar.gz - go build -o goserver main.go diff --git a/example/goserver/go.mod b/example/goserver/go.mod index 53fdecb..4107413 100644 --- a/example/goserver/go.mod +++ b/example/goserver/go.mod @@ -1,5 +1,3 @@ module goserver go 1.13 - -require go.uber.org/automaxprocs v1.5.1 diff --git a/example/goserver/go.sum b/example/goserver/go.sum deleted file mode 100644 index c9f3ed5..0000000 --- a/example/goserver/go.sum +++ /dev/null @@ -1,24 +0,0 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= -github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -go.uber.org/automaxprocs v1.5.1 h1:e1YG66Lrk73dn4qhg8WFSvhF0JuFQF0ERIp4rpuV8Qk= -go.uber.org/automaxprocs v1.5.1/go.mod h1:BF4eumQw0P9GtnuxxovUd06vwm1o18oMzFtK66vU6XU= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/html/index.html b/html/index.html index 48f118a..a513cce 100644 --- a/html/index.html +++ b/html/index.html @@ -1 +1 @@ -Welcome to OpenResty!

Welcome to ngxway!

When you see this page, the ngxway is successfully installed and working. For online documentation and support please refer to our site.

Thank you very much.

+Welcome to ngxway!

Welcome to ngxway!

When you see this page, the ngxway is successfully installed and working. For online documentation and support please refer to our site.

Thank you very much.

diff --git a/ngxway.conf b/ngxway.conf index bb381fe..c8738ec 100644 --- a/ngxway.conf +++ b/ngxway.conf @@ -10,3 +10,15 @@ ngxway_addr=127.0.0.1:8090 local_volume_logs_dir=/tmp/logs # if the request takes longer than slow_time(the unit is seconds), it will be add to the slow log. slow_time=0.5 +# The max cup processors. +max_ncpu=8 +# The network option of docker.[bridge/host] +docker_network=host +# The linux system params in docker. +tcp_syncookies=0 +tcp_max_tw_buckets=700 +tcp_tw_reuse=1 +somaxconn=262155 +ip_local_port_range=1024 65535 +soft_nofile=1048576 +hard_nofile=1048576 diff --git a/scripts/common.sh b/scripts/common.sh index 52505ae..db0fe39 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -6,6 +6,15 @@ env=`sed '/^env=/!d;s/.*=//' ${ngxwayConfigFile}` ngxwayAddr=`sed '/^ngxway_addr=/!d;s/.*=//' ${ngxwayConfigFile}` localVolumeLogsDir=`sed '/^local_volume_logs_dir=/!d;s/.*=//' ${ngxwayConfigFile}` slowTime=`sed '/^slow_time=/!d;s/.*=//' ${ngxwayConfigFile}` +maxNCPU=`sed '/^max_ncpu=/!d;s/.*=//' ${ngxwayConfigFile}` +dockerNetwork=`sed '/^docker_network=/!d;s/.*=//' ${ngxwayConfigFile}` +tcpSyncookies=`sed '/^tcp_syncookies=/!d;s/.*=//' ${ngxwayConfigFile}` +tcpMaxTWBuckets=`sed '/^tcp_max_tw_buckets=/!d;s/.*=//' ${ngxwayConfigFile}` +tcpTWReuse=`sed '/^tcp_tw_reuse=/!d;s/.*=//' ${ngxwayConfigFile}` +soMaxConn=`sed '/^somaxconn=/!d;s/.*=//' ${ngxwayConfigFile}` +ipLocalPortRange=`sed '/^ip_local_port_range=/!d;s/.*=//' ${ngxwayConfigFile}` +softNoFile=`sed '/^soft_nofile=/!d;s/.*=//' ${ngxwayConfigFile}` +hardNoFile=`sed '/^hard_nofile=/!d;s/.*=//' ${ngxwayConfigFile}` # The common variables s here. # ================================ @@ -30,6 +39,15 @@ benchmarkHTMLFile="${ngxwayPath}/html/benchmark.html" # The common functions is here. # ================================ +function checkNgxwayConfig() { + if [ "$dockerNetwork" == "bridge" ] || [ "$dockerNetwork" == "host" ] ;then + echo "ok" + return + fi + + echo "failed" +} + function computeSignedRequest() { timeStamp=`date +%s`