Commit 3effedf0 authored by wongoo's avatar wongoo

fix import & merge latest

parent 6664cf2e
# Run Hello Demo
## 1. prepare
```bash
git clone https://github.com/dubbogo/getty.git
cd getty/demo/hello
```
# run server
go run tcp/server/server.go
## 2. run server
# run client
go run tcp/client/client.go
run server:
`go run tcp/server/server.go`
Or run server in task pool mode:
```bash
go run tcp/server/server.go -taskPool=true \
-task_queue_length=100 \
-task_queue_number=4 \
-task_pool_size=2000
```
## 3. run client
```bash
go run tcp/client/client.go
```
\ No newline at end of file
......@@ -9,11 +9,10 @@ package hello
import (
"github.com/dubbogo/getty"
"time"
)
const (
CronPeriod = 20 * time.Second
CronPeriod = 20e9
WritePkgTimeout = 1e8
)
......
......@@ -8,11 +8,13 @@
package hello
import (
"github.com/dubbogo/getty"
"time"
)
import (
"github.com/dubbogo/getty"
)
type MessageHandler struct {
SessionOnOpen func(session getty.Session)
}
......@@ -45,7 +47,7 @@ func (h *MessageHandler) OnMessage(session getty.Session, pkg interface{}) {
func (h *MessageHandler) OnCron(session getty.Session) {
active := session.GetActive()
if CronPeriod.Nanoseconds() < time.Since(active).Nanoseconds() {
if CronPeriod < time.Since(active).Nanoseconds() {
log.Infof("OnCorn session{%s} timeout{%s}", session.Stat(), time.Since(active).String())
session.Close()
}
......
......@@ -9,6 +9,9 @@ package hello
import (
"errors"
)
import (
"github.com/dubbogo/getty"
)
......
......@@ -9,7 +9,13 @@ package main
import (
"flag"
)
import (
"github.com/dubbogo/getty"
)
import (
"github.com/dubbogo/getty/demo/hello"
"github.com/dubbogo/getty/demo/hello/tcp"
"github.com/dubbogo/getty/demo/util"
......
......@@ -9,13 +9,18 @@ package tcp
import (
"fmt"
"github.com/dubbogo/getty"
"github.com/dubbogo/getty/demo/hello"
"net"
"time"
)
import (
"github.com/dubbogo/getty"
)
import (
"github.com/dubbogo/getty/demo/hello"
)
var (
pkgHandler = &hello.PackageHandler{}
eventListener = &hello.MessageHandler{}
......@@ -58,7 +63,7 @@ func InitialSession(session getty.Session) (err error) {
session.SetWQLen(512)
session.SetReadTimeout(time.Second)
session.SetWriteTimeout(5 * time.Second)
session.SetCronPeriod(int(hello.CronPeriod.Nanoseconds() / 1e6))
session.SetCronPeriod(int(hello.CronPeriod / 1e6))
session.SetWaitTime(time.Second)
session.SetPkgHandler(pkgHandler)
......
......@@ -9,7 +9,14 @@ package main
import (
"flag"
)
import (
"github.com/dubbogo/getty"
gxsync "github.com/dubbogo/gost/sync"
)
import (
"github.com/dubbogo/getty/demo/hello/tcp"
"github.com/dubbogo/getty/demo/util"
)
......@@ -22,7 +29,7 @@ var (
)
var (
taskPoll *getty.TaskPool
taskPoll *gxsync.TaskPool
)
func main() {
......@@ -33,10 +40,10 @@ func main() {
options := []getty.ServerOption{getty.WithLocalAddress(":8090")}
if *taskPollMode {
taskPoll = getty.NewTaskPool(
getty.WithTaskPoolTaskQueueLength(*taskPollQueueLength),
getty.WithTaskPoolTaskQueueNumber(*taskPollQueueNumber),
getty.WithTaskPoolTaskPoolSize(*taskPollSize),
taskPoll = gxsync.NewTaskPool(
gxsync.WithTaskPoolTaskQueueLength(*taskPollQueueLength),
gxsync.WithTaskPoolTaskQueueNumber(*taskPollQueueNumber),
gxsync.WithTaskPoolTaskPoolSize(*taskPollSize),
)
}
......
......@@ -9,7 +9,9 @@
package util
import "syscall"
import (
"syscall"
)
func SetLimit() {
var rLimit syscall.Rlimit
......
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