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
d63a5e25
Commit
d63a5e25
authored
Sep 03, 2016
by
alexstocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
elasitic sleep time in client.go:(Client)RunTimeLoop
parent
ee22cae5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
13 deletions
+14
-13
README.md
README.md
+3
-1
client.go
client.go
+11
-3
utils.go
utils.go
+0
-9
No files found.
README.md
View file @
d63a5e25
...
@@ -21,7 +21,9 @@
...
@@ -21,7 +21,9 @@
>
>
> 5 session.go:(Session)SetConn
> 5 session.go:(Session)SetConn
>
>
> 6 version: 0.3.01
> 6 add elastic sleep time machanism in client.go:(Client)RunEventLoop
>
> 7 version: 0.3.01
-
2016/09/02
-
2016/09/02
> 1 add session.go:(gettyConn)close and session.go:(Session)dispose
> 1 add session.go:(gettyConn)close and session.go:(Session)dispose
...
...
client.go
View file @
d63a5e25
...
@@ -21,6 +21,8 @@ import (
...
@@ -21,6 +21,8 @@ import (
const
(
const
(
defaultInterval
=
3e9
// 3s
defaultInterval
=
3e9
// 3s
connectTimeout
=
5e9
maxTimes
=
10
)
)
type
empty
struct
{}
type
empty
struct
{}
...
@@ -70,7 +72,7 @@ func (this *Client) dial() net.Conn {
...
@@ -70,7 +72,7 @@ func (this *Client) dial() net.Conn {
if
this
.
IsClosed
()
{
if
this
.
IsClosed
()
{
return
nil
return
nil
}
}
conn
,
err
=
net
.
DialTimeout
(
"tcp"
,
this
.
addr
,
this
.
interval
)
conn
,
err
=
net
.
DialTimeout
(
"tcp"
,
this
.
addr
,
connectTimeout
)
if
err
==
nil
{
if
err
==
nil
{
return
conn
return
conn
}
}
...
@@ -129,7 +131,7 @@ func (this *Client) RunEventLoop(newSession SessionCallback) {
...
@@ -129,7 +131,7 @@ func (this *Client) RunEventLoop(newSession SessionCallback) {
this
.
wg
.
Add
(
1
)
this
.
wg
.
Add
(
1
)
go
func
()
{
go
func
()
{
var
num
,
max
int
var
num
,
max
,
times
int
defer
this
.
wg
.
Done
()
defer
this
.
wg
.
Done
()
this
.
Lock
()
this
.
Lock
()
...
@@ -145,10 +147,16 @@ func (this *Client) RunEventLoop(newSession SessionCallback) {
...
@@ -145,10 +147,16 @@ func (this *Client) RunEventLoop(newSession SessionCallback) {
num
=
this
.
sessionNum
()
num
=
this
.
sessionNum
()
// log.Info("current client connction number:%d", num)
// log.Info("current client connction number:%d", num)
if
max
<=
num
{
if
max
<=
num
{
time
.
Sleep
(
this
.
interval
)
times
++
if
maxTimes
<
times
{
times
=
maxTimes
}
time
.
Sleep
(
time
.
Duration
(
times
*
defaultInterval
))
continue
continue
}
}
times
=
0
this
.
connect
()
this
.
connect
()
// time.Sleep(this.interval) // build this.number connections asap
}
}
}()
}()
}
}
...
...
utils.go
View file @
d63a5e25
...
@@ -14,21 +14,12 @@ import (
...
@@ -14,21 +14,12 @@ import (
"encoding/binary"
"encoding/binary"
"net"
"net"
"strconv"
"strconv"
"time"
)
)
func
HostAddress
(
host
string
,
port
int
)
string
{
func
HostAddress
(
host
string
,
port
int
)
string
{
return
net
.
JoinHostPort
(
host
,
strconv
.
Itoa
(
port
))
return
net
.
JoinHostPort
(
host
,
strconv
.
Itoa
(
port
))
}
}
func
dial
(
addr
string
)
(
net
.
Conn
,
error
)
{
return
net
.
Dial
(
"tcp"
,
addr
)
}
func
dialTimeout
(
addr
string
,
timeout
time
.
Duration
)
(
net
.
Conn
,
error
)
{
return
net
.
DialTimeout
(
"tcp"
,
addr
,
timeout
)
}
////////////////////////////////////////
////////////////////////////////////////
// enc/dec
// enc/dec
////////////////////////////////////////
////////////////////////////////////////
...
...
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