Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
getty
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
getty
Commits
3effedf0
Commit
3effedf0
authored
Jul 22, 2019
by
wongoo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix import & merge latest
parent
6664cf2e
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
56 additions
and
19 deletions
+56
-19
README.md
demo/hello/README.md
+17
-4
consts.go
demo/hello/consts.go
+1
-2
messagelistener.go
demo/hello/messagelistener.go
+5
-3
pkghandler.go
demo/hello/pkghandler.go
+3
-0
client.go
demo/hello/tcp/client/client.go
+6
-0
config.go
demo/hello/tcp/config.go
+9
-4
server.go
demo/hello/tcp/server/server.go
+12
-5
limit_linux.go
demo/util/limit_linux.go
+3
-1
No files found.
demo/hello/README.md
View file @
3effedf0
# 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
demo/hello/consts.go
View file @
3effedf0
...
...
@@ -9,11 +9,10 @@ package hello
import
(
"github.com/dubbogo/getty"
"time"
)
const
(
CronPeriod
=
20
*
time
.
Second
CronPeriod
=
20
e9
WritePkgTimeout
=
1e8
)
...
...
demo/hello/messagelistener.go
View file @
3effedf0
...
...
@@ -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
()
}
...
...
demo/hello/pkghandler.go
View file @
3effedf0
...
...
@@ -9,6 +9,9 @@ package hello
import
(
"errors"
)
import
(
"github.com/dubbogo/getty"
)
...
...
demo/hello/tcp/client/client.go
View file @
3effedf0
...
...
@@ -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"
...
...
demo/hello/tcp/config.go
View file @
3effedf0
...
...
@@ -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
)
...
...
demo/hello/tcp/server/server.go
View file @
3effedf0
...
...
@@ -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
*
g
etty
.
TaskPool
taskPoll
*
g
xsync
.
TaskPool
)
func
main
()
{
...
...
@@ -33,10 +40,10 @@ func main() {
options
:=
[]
getty
.
ServerOption
{
getty
.
WithLocalAddress
(
":8090"
)}
if
*
taskPollMode
{
taskPoll
=
g
etty
.
NewTaskPool
(
g
etty
.
WithTaskPoolTaskQueueLength
(
*
taskPollQueueLength
),
g
etty
.
WithTaskPoolTaskQueueNumber
(
*
taskPollQueueNumber
),
g
etty
.
WithTaskPoolTaskPoolSize
(
*
taskPollSize
),
taskPoll
=
g
xsync
.
NewTaskPool
(
g
xsync
.
WithTaskPoolTaskQueueLength
(
*
taskPollQueueLength
),
g
xsync
.
WithTaskPoolTaskQueueNumber
(
*
taskPollQueueNumber
),
g
xsync
.
WithTaskPoolTaskPoolSize
(
*
taskPollSize
),
)
}
...
...
demo/util/limit_linux.go
View file @
3effedf0
...
...
@@ -9,7 +9,9 @@
package
util
import
"syscall"
import
(
"syscall"
)
func
SetLimit
()
{
var
rLimit
syscall
.
Rlimit
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment