Skip to content

Commit

Permalink
fix: expose more config options to ngxway.conf
Browse files Browse the repository at this point in the history
  • Loading branch information
WGrape committed Mar 8, 2023
1 parent 7a9ac67 commit 6565f16
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 45 deletions.
35 changes: 21 additions & 14 deletions bin/ngxway
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions example/goserver/build.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions example/goserver/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module goserver

go 1.13

require go.uber.org/automaxprocs v1.5.1
24 changes: 0 additions & 24 deletions example/goserver/go.sum

This file was deleted.

2 changes: 1 addition & 1 deletion html/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html><head><meta content="text/html;charset=utf-8" http-equiv="Content-Type"><meta content="utf-8" http-equiv="encoding"><title>Welcome to OpenResty!</title><style>body{width: 35em;margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; }</style></head><body><h1>Welcome to ngxway!</h1><p>When you see this page, the ngxway is successfully installed and working. For online documentation and support please refer to our <a href="https://github.com/WGrape/ngxway">site</a>.</p><p><em>Thank you very much.</em></p>
<!DOCTYPE html><html><head><meta content="text/html;charset=utf-8" http-equiv="Content-Type"><meta content="utf-8" http-equiv="encoding"><title>Welcome to ngxway!</title><style>body{width: 35em;margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; }</style></head><body><h1>Welcome to ngxway!</h1><p>When you see this page, the ngxway is successfully installed and working. For online documentation and support please refer to our <a href="https://github.com/WGrape/ngxway">site</a>.</p><p><em>Thank you very much.</em></p>
12 changes: 12 additions & 0 deletions ngxway.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
# ================================
Expand All @@ -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`

Expand Down

0 comments on commit 6565f16

Please sign in to comment.