Commit 884e61cc authored by alexstocks's avatar alexstocks

modify configuration

parent fadcc00a
......@@ -32,24 +32,54 @@ var (
)
type (
GettySessionParam struct {
TcpNoDelay bool `default:"true"`
TcpKeepAlive bool `default:"true"`
TcpRBufSize int `default:"262144"`
TcpWBufSize int `default:"65536"`
PkgRQSize int `default:"1024"`
PkgWQSize int `default:"1024"`
TcpReadTimeout string `default:"1s"`
tcpReadTimeout time.Duration
TcpWriteTimeout string `default:"5s"`
tcpWriteTimeout time.Duration
WaitTimeout string `default:"7s"`
waitTimeout time.Duration
SessionName string `default:"echo-client"`
}
// Config holds supported types by the multiconfig package
Config struct {
LocalHost string `default:"127.0.0.1"`
LocalHost string `default:"127.0.0.1"`
// server
ServerHost string `default:"127.0.0.1"`
ServerPort int `default:"10000"`
ProfilePort int `default:"10086"`
// session pool
ConnectionNum int `default:"16"`
ConnectInterval string `default:"5s"`
connectInterval time.Duration
// heartbeat
HeartbeatPeriod string `default:"15s"`
heartbeatPeriod time.Duration
// session
SessionTimeout string `default:"60s"`
sessionTimeout time.Duration
EchoTimes int `default:"10"`
// echo
EchoString string `default:"hello"`
EchoTimes int `default:"10"`
// app
FailFastTimeout string `default:"5s"`
failFastTimeout time.Duration
// session tcp parameters
GettySessionParam GettySessionParam `required:"true"`
}
)
......@@ -86,6 +116,26 @@ func initConf() {
panic(fmt.Sprintf("time.ParseDuration(SessionTimeout{%#v}) = error{%v}", conf.SessionTimeout, err))
return
}
conf.failFastTimeout, err = time.ParseDuration(conf.FailFastTimeout)
if err != nil {
panic(fmt.Sprintf("time.ParseDuration(FailFastTimeout{%#v}) = error{%v}", conf.FailFastTimeout, err))
return
}
conf.GettySessionParam.tcpReadTimeout, err = time.ParseDuration(conf.GettySessionParam.TcpReadTimeout)
if err != nil {
panic(fmt.Sprintf("time.ParseDuration(TcpReadTimeout{%#v}) = error{%v}", conf.GettySessionParam.TcpReadTimeout, err))
return
}
conf.GettySessionParam.tcpWriteTimeout, err = time.ParseDuration(conf.GettySessionParam.TcpWriteTimeout)
if err != nil {
panic(fmt.Sprintf("time.ParseDuration(TcpWriteTimeout{%#v}) = error{%v}", conf.GettySessionParam.TcpWriteTimeout, err))
return
}
conf.GettySessionParam.waitTimeout, err = time.ParseDuration(conf.GettySessionParam.WaitTimeout)
if err != nil {
panic(fmt.Sprintf("time.ParseDuration(WaitTimeout{%#v}) = error{%v}", conf.GettySessionParam.WaitTimeout, err))
return
}
gocolor.Info("config{%#v}\n", conf)
......
......@@ -30,21 +30,7 @@ import (
)
const (
tcpRBufSize = 256 * 1024
tcpWBufSize = 64 * 1024
pkgRQSize = 1024
pkgWQSize = 64
tcpReadTimeout = 1e9
tcpWriteTimeout = 5e9
waitTimeout = 5e9 // 5s
echoSessionTimeout = 5e9
maxSessionNum = 100
sessionName = "echo-client"
)
const (
survivalTimeout = 3e9
pprofPath = "/debug/pprof/"
pprofPath = "/debug/pprof/"
)
var (
......@@ -89,20 +75,20 @@ func newSession(session *getty.Session) error {
panic(fmt.Sprintf("%s, session.conn{%#v} is not tcp connection\n", session.Stat(), session.Conn()))
}
tcpConn.SetNoDelay(true)
tcpConn.SetReadBuffer(tcpRBufSize)
tcpConn.SetWriteBuffer(tcpWBufSize)
tcpConn.SetKeepAlive(true)
tcpConn.SetNoDelay(conf.GettySessionParam.TcpNoDelay)
tcpConn.SetKeepAlive(conf.GettySessionParam.TcpKeepAlive)
tcpConn.SetReadBuffer(conf.GettySessionParam.TcpRBufSize)
tcpConn.SetWriteBuffer(conf.GettySessionParam.TcpWBufSize)
session.SetName(sessionName)
session.SetName(conf.GettySessionParam.SessionName)
session.SetPkgHandler(NewEchoPackageHandler())
session.SetEventListener(newEchoMessageHandler())
session.SetRQLen(pkgRQSize)
session.SetWQLen(pkgWQSize)
session.SetReadDeadline(tcpReadTimeout)
session.SetWriteDeadline(tcpWriteTimeout)
session.SetRQLen(conf.GettySessionParam.PkgRQSize)
session.SetWQLen(conf.GettySessionParam.PkgWQSize)
session.SetReadDeadline(conf.GettySessionParam.tcpReadTimeout)
session.SetWriteDeadline(conf.GettySessionParam.tcpWriteTimeout)
session.SetCronPeriod((int)(conf.heartbeatPeriod.Nanoseconds() / 1e6))
session.SetWaitTime(waitTimeout)
session.SetWaitTime(conf.GettySessionParam.waitTimeout)
log.Debug("client new session:%s\n", session.Stat())
return nil
......@@ -132,7 +118,7 @@ func initSignal() {
case syscall.SIGHUP:
// reload()
default:
go time.AfterFunc(survivalTimeout, func() {
go time.AfterFunc(conf.failFastTimeout, func() {
log.Warn("app exit now by force...")
os.Exit(1)
})
......@@ -152,7 +138,7 @@ func echo() {
pkg.H.Sequence = atomic.AddUint32(&reqID, 1)
// pkg.H.ServiceID = 0
pkg.H.Command = echoCmd
pkg.B = echoMessage
pkg.B = conf.EchoString
pkg.H.Len = (uint16)(len(pkg.B))
if session := client.selectSession(); session != nil {
......
......@@ -51,7 +51,6 @@ const (
echoHeartbeatRequestString = "ping"
echoHeartbeatResponseString = "pong"
echoMessage = "Hello, getty!"
)
var (
......
......@@ -32,7 +32,7 @@ usage() {
}
start() {
APP_LOG_PATH="${PROJECT_HOME}logs/"
APP_LOG_PATH=${PROJECT_HOME}"logs/"
mkdir -p ${APP_LOG_PATH}
APP_BIN=${PROJECT_HOME}sbin/${APP_NAME}
chmod u+x ${APP_BIN}
......
# dubbogo application configure script
# getty application configure script
# ******************************************************
# DESC : application environment variable
# AUTHOR : Alex Stocks
......
#!/usr/bin/env bash
# ******************************************************
# DESC : build script for release env
# AUTHOR : Alex Stocks
# VERSION : 1.0
# LICENCE : LGPL V3
# EMAIL : alexstocks@foxmail.com
# MOD : 2016-07-12 16:25
# FILE : release.sh
# ******************************************************
set -e
export GOOS=linux
export GOARCH=amd64
PROFILE=release
PROJECT_HOME=`pwd`
if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then
. ${PROJECT_HOME}/assembly/common/app.properties
fi
if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then
. ${PROJECT_HOME}/assembly/common/build.sh
fi
#!/usr/bin/env bash
# ******************************************************
# DESC : build script for release env
# AUTHOR : Alex Stocks
# VERSION : 1.0
# LICENCE : LGPL V3
# EMAIL : alexstocks@foxmail.com
# MOD : 2016-07-12 16:25
# FILE : release.sh
# ******************************************************
set -e
export GOOS=windows
export GOARCH=amd64
PROFILE=release
PROJECT_HOME=`pwd`
if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then
. ${PROJECT_HOME}/assembly/common/app.properties
fi
if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then
. ${PROJECT_HOME}/assembly/common/build.sh
fi
......@@ -3,7 +3,7 @@
# DESC : build script for test env
# AUTHOR : Alex Stocks
# VERSION : 1.0
# LICENCE : LGPL V3
# LICENCE : Apache License 2.0
# EMAIL : alexstocks@foxmail.com
# MOD : 2016-07-12 16:34
# FILE : test.sh
......
# toml configure file
# toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写
# host
LocalHost = "127.0.0.1"
# server
ServerHost = "192.168.35.1"
ServerPort = 10000
ProfilePort = 10080
# connection pool
# 连接池连接数目
ConnectionNum = 2
# 当连接失败或者连接断开时,连接池中重连的间隔时间
ConnectInterval = "5s"
# session
# client与server之间连接的心跳周期
HeartbeatPeriod = "10s"
# client与server之间连接的超时时间
SessionTimeout = "20s"
# client
# client echo request string
EchoString = "Hello, getty!"
# 发送echo请求次数
EchoTimes = 100000
# app fail fast
FailFastTimeout = "3s"
# tcp
[GettySessionParam]
TcpNoDelay = true
TcpKeepAlive = true
TcpRBufSize = 262144
TcpWBufSize = 65536
PkgRQSize = 512
PkgWQSize = 256
TcpReadTimeout = 1e9
TcpWriteTimeout = 5e9
WaitTimeout = 1e9 // 1s
SessionName = "echo-client"
#!/usr/bin/env bash
# ******************************************************
# DESC : getty app devops script
# AUTHOR : Alex Stocks
# VERSION : 1.0
# LICENCE : LGPL V3
# EMAIL : alexstocks@foxmail.com
# MOD : 2016-05-13 02:01
# FILE : load.sh
# ******************************************************
APP_NAME="echo_client"
APP_ARGS=""
PROJECT_HOME=""
OS_NAME=`uname`
if [[ ${OS_NAME} == "Linux" ]]; then
PROJECT_HOME=`pwd`
PROJECT_HOME=${PROJECT_HOME}"/"
fi
export APP_CONF_FILE=${PROJECT_HOME}"conf/config.toml"
export APP_LOG_CONF_FILE=${PROJECT_HOME}"conf/log.xml"
usage() {
echo "Usage: $0 start"
echo " $0 stop"
echo " $0 term"
echo " $0 restart"
echo " $0 list"
exit
}
start() {
APP_LOG_PATH=${PROJECT_HOME}"logs/"
mkdir -p ${APP_LOG_PATH}
APP_BIN=${PROJECT_HOME}sbin/${APP_NAME}
chmod u+x ${APP_BIN}
# CMD="nohup ${APP_BIN} ${APP_ARGS} >>${APP_NAME}.nohup.out 2>&1 &"
CMD="${APP_BIN}"
eval ${CMD}
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'`
if [[ ${OS_NAME} != "Linux" ]]; then
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'`
fi
if [ "${PID}" != "" ];
then
for p in ${PID}
do
echo "start ${APP_NAME} ( pid =" ${p} ")"
done
fi
}
stop() {
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'`
if [[ ${OS_NAME} != "Linux" ]]; then
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'`
fi
if [ "${PID}" != "" ];
then
for ps in ${PID}
do
echo "kill -SIGINT ${APP_NAME} ( pid =" ${ps} ")"
kill -2 ${ps}
done
fi
}
term() {
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'`
if [[ ${OS_NAME} != "Linux" ]]; then
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'`
fi
if [ "${PID}" != "" ];
then
for ps in ${PID}
do
echo "kill -9 ${APP_NAME} ( pid =" ${ps} ")"
kill -9 ${ps}
done
fi
}
list() {
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{printf("%s,%s,%s,%s\n", $1, $2, $9, $10)}'`
if [[ ${OS_NAME} != "Linux" ]]; then
PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{printf("%s,%s,%s,%s,%s\n", $1, $4, $6, $7, $8)}'`
fi
if [ "${PID}" != "" ];
then
echo "list ${APP_NAME}"
if [[ ${OS_NAME} == "Linux" ]]; then
echo "index: user, pid, start, duration"
else
echo "index: PID, WINPID, UID, STIME, COMMAND"
fi
idx=0
for ps in ${PID}
do
echo "${idx}: ${ps}"
((idx ++))
done
fi
}
opt=$1
case C"$opt" in
Cstart)
start
;;
Cstop)
stop
;;
Cterm)
term
;;
Crestart)
term
start
;;
Clist)
list
;;
C*)
usage
;;
esac
# toml configure file
# toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写
# host
LocalHost = "127.0.0.1"
# server
ServerHost = "192.168.35.1"
ServerPort = 10000
ProfilePort = 10080
# connection pool
# 连接池连接数目
ConnectionNum = 2
# 当连接失败或者连接断开时,连接池中重连的间隔时间
ConnectInterval = "5s"
# session
# client与server之间连接的心跳周期
HeartbeatPeriod = "10s"
# client与server之间连接的超时时间
SessionTimeout = "20s"
# client
# client echo request string
EchoString = "Hello, getty!"
# 发送echo请求次数
EchoTimes = 100000
# app fail fast
FailFastTimeout = "3s"
# tcp
[GettySessionParam]
TcpNoDelay = true
TcpKeepAlive = true
TcpRBufSize = 262144
TcpWBufSize = 65536
PkgRQSize = 512
PkgWQSize = 256
TcpReadTimeout = 1e9
TcpWriteTimeout = 5e9
WaitTimeout = 1e9 // 1s
SessionName = "echo-client"
......@@ -32,14 +32,40 @@ var (
)
type (
GettySessionParam struct {
TcpNoDelay bool `default:"true"`
TcpKeepAlive bool `default:"true"`
TcpRBufSize int `default:"262144"`
TcpWBufSize int `default:"65536"`
PkgRQSize int `default:"1024"`
PkgWQSize int `default:"1024"`
TcpReadTimeout string `default:"1s"`
tcpReadTimeout time.Duration
TcpWriteTimeout string `default:"5s"`
tcpWriteTimeout time.Duration
WaitTimeout string `default:"7s"`
waitTimeout time.Duration
SessionName string `default:"echo-client"`
}
// Config holds supported types by the multiconfig package
Config struct {
// local address
Host string `default:"127.0.0.1"`
Ports []string `default:["10000"]`
ProfilePort int `default:"10086"`
// session
SessionTimeout string `default:"60s"`
sessionTimeout time.Duration
SessionNumber int `default:"1000"`
// app
FailFastTimeout string `default:"5s"`
failFastTimeout time.Duration
// session tcp parameters
GettySessionParam GettySessionParam `required:"true"`
}
)
......@@ -66,6 +92,27 @@ func initConf() {
panic(fmt.Sprintf("time.ParseDuration(SessionTimeout{%#v}) = error{%v}", conf.SessionTimeout, err))
return
}
conf.failFastTimeout, err = time.ParseDuration(conf.FailFastTimeout)
if err != nil {
panic(fmt.Sprintf("time.ParseDuration(FailFastTimeout{%#v}) = error{%v}", conf.FailFastTimeout, err))
return
}
conf.GettySessionParam.tcpReadTimeout, err = time.ParseDuration(conf.GettySessionParam.TcpReadTimeout)
if err != nil {
panic(fmt.Sprintf("time.ParseDuration(TcpReadTimeout{%#v}) = error{%v}", conf.GettySessionParam.TcpReadTimeout, err))
return
}
conf.GettySessionParam.tcpWriteTimeout, err = time.ParseDuration(conf.GettySessionParam.TcpWriteTimeout)
if err != nil {
panic(fmt.Sprintf("time.ParseDuration(TcpWriteTimeout{%#v}) = error{%v}", conf.GettySessionParam.TcpWriteTimeout, err))
return
}
conf.GettySessionParam.waitTimeout, err = time.ParseDuration(conf.GettySessionParam.WaitTimeout)
if err != nil {
panic(fmt.Sprintf("time.ParseDuration(WaitTimeout{%#v}) = error{%v}", conf.GettySessionParam.WaitTimeout, err))
return
}
gocolor.Info("config{%#v}\n", conf)
// log
......
......@@ -87,7 +87,7 @@ func (this *EchoMessageHandler) OnOpen(session *getty.Session) error {
)
this.rwlock.RLock()
if maxSessionNum < len(this.sessionMap) {
if conf.SessionNumber < len(this.sessionMap) {
err = errTooManySessions
}
this.rwlock.RUnlock()
......
......@@ -28,21 +28,7 @@ import (
)
const (
tcpRBufSize = 256 * 1024
tcpWBufSize = 64 * 1024
pkgRQSize = 1024
pkgWQSize = 64
tcpReadTimeout = 1e9
tcpWriteTimeout = 5e9
waitTimeout = 5e9 // 5s
echoSessionTimeout = 5e9
maxSessionNum = 100
sessionName = "echo-server"
)
const (
survivalTimeout = 3e9
pprofPath = "/debug/pprof/"
pprofPath = "/debug/pprof/"
)
var (
......@@ -92,19 +78,20 @@ func newSession(session *getty.Session) error {
panic(fmt.Sprintf("%s, session.conn{%#v} is not tcp connection\n", session.Stat(), session.Conn()))
}
tcpConn.SetNoDelay(true)
tcpConn.SetReadBuffer(tcpRBufSize)
tcpConn.SetWriteBuffer(tcpWBufSize)
tcpConn.SetKeepAlive(true)
tcpConn.SetNoDelay(conf.GettySessionParam.TcpNoDelay)
tcpConn.SetKeepAlive(conf.GettySessionParam.TcpKeepAlive)
tcpConn.SetReadBuffer(conf.GettySessionParam.TcpRBufSize)
tcpConn.SetWriteBuffer(conf.GettySessionParam.TcpWBufSize)
session.SetName(sessionName)
session.SetName(conf.GettySessionParam.SessionName)
session.SetPkgHandler(NewEchoPackageHandler())
session.SetEventListener(newEchoMessageHandler())
session.SetRQLen(pkgRQSize)
session.SetWQLen(pkgWQSize)
session.SetReadDeadline(tcpReadTimeout)
session.SetWriteDeadline(tcpWriteTimeout)
session.SetWaitTime(waitTimeout)
session.SetRQLen(conf.GettySessionParam.PkgRQSize)
session.SetWQLen(conf.GettySessionParam.PkgWQSize)
session.SetReadDeadline(conf.GettySessionParam.tcpReadTimeout)
session.SetWriteDeadline(conf.GettySessionParam.tcpWriteTimeout)
session.SetCronPeriod((int)(conf.sessionTimeout.Nanoseconds() / 1e6))
session.SetWaitTime(conf.GettySessionParam.waitTimeout)
log.Debug("app accepts new session:%s\n", session.Stat())
return nil
......@@ -165,7 +152,7 @@ func initSignal() {
case syscall.SIGHUP:
// reload()
default:
go time.AfterFunc(survivalTimeout, func() {
go time.AfterFunc(conf.failFastTimeout, func() {
log.Warn("app exit now by force...")
os.Exit(1)
})
......
# dubbogo application configure script
# getty application configure script
# ******************************************************
# DESC : application environment variable
# AUTHOR : Alex Stocks
......
# toml configure file
# toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写
# Host = "127.0.0.1"
Host = "192.168.35.1"
Ports = ["10000", "20000"]
ProfilePort = 10086
# session
# client与server之间连接的超时时间
SessionTimeout = "20s"
SessionNumber = 700
# app
FailFastTimeout = "3s"
# tcp
[GettySessionParam]
TcpNoDelay = true
TcpKeepAlive = true
TcpRBufSize = 262144
TcpWBufSize = 524288
PkgRQSize = 1024
PkgWQSize = 512
TcpReadTimeout = 1e9
TcpWriteTimeout = 5e9
WaitTimeout = 1e9 // 1s
SessionName = "echo-server"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment