Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vladimir Barsukov
zGo
Commits
86d85eca
Commit
86d85eca
authored
Nov 19, 2023
by
Vladimir Barsukov
Browse files
fix
parent
5b2da0e8
Changes
4
Show whitespace changes
Inline
Side-by-side
zdb/pool.go
View file @
86d85eca
...
@@ -2,7 +2,6 @@ package zdb
...
@@ -2,7 +2,6 @@ package zdb
import
(
import
(
"context"
"context"
"errors"
"fmt"
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/jackc/pgx/v5/pgxpool"
"log"
"log"
...
@@ -86,13 +85,22 @@ func (d *Pool) WithContext(ctx context.Context) *Pool {
...
@@ -86,13 +85,22 @@ func (d *Pool) WithContext(ctx context.Context) *Pool {
}
}
func
(
d
*
Pool
)
WithTimeout
(
dur
time
.
Duration
)
*
Pool
{
func
(
d
*
Pool
)
WithTimeout
(
dur
time
.
Duration
)
*
Pool
{
ctx
,
_
:=
context
.
WithTimeout
(
d
.
ctx
,
dur
)
ctx
,
cancel
:=
context
.
WithTimeout
(
d
.
ctx
,
dur
)
go
func
()
{
time
.
Sleep
(
dur
)
cancel
()
}()
return
d
.
WithContext
(
ctx
)
return
d
.
WithContext
(
ctx
)
}
}
func
(
d
*
Pool
)
WithDeadline
(
dur
time
.
Time
)
*
Pool
{
func
(
d
*
Pool
)
WithDeadline
(
dur
time
.
Time
)
*
Pool
{
ctx
,
_
:=
context
.
WithDeadline
(
d
.
ctx
,
dur
)
ctx
,
cancel
:=
context
.
WithDeadline
(
d
.
ctx
,
dur
)
go
func
()
{
time
.
Sleep
(
time
.
Since
(
dur
))
cancel
()
}()
return
d
.
WithContext
(
ctx
)
return
d
.
WithContext
(
ctx
)
}
}
...
@@ -113,7 +121,7 @@ func (d *Pool) NewConn(mode connMode, pgConnString string) error {
...
@@ -113,7 +121,7 @@ func (d *Pool) NewConn(mode connMode, pgConnString string) error {
q
.
Index
=
len
(
d
.
SrvAsync
)
q
.
Index
=
len
(
d
.
SrvAsync
)
d
.
SrvAsync
=
append
(
d
.
SrvAsync
,
q
)
d
.
SrvAsync
=
append
(
d
.
SrvAsync
,
q
)
default
:
default
:
return
errors
.
New
(
"unknown mode"
)
panic
(
"unknown mode"
)
}
}
return
err
return
err
...
...
zdebug/zdebug.go
View file @
86d85eca
...
@@ -14,14 +14,14 @@ func NewMonitor(secs int) {
...
@@ -14,14 +14,14 @@ func NewMonitor(secs int) {
var
memMax
uint64
var
memMax
uint64
for
{
for
{
<-
time
.
After
(
time
.
Duration
(
secs
)
*
time
.
Second
)
time
.
Sleep
(
time
.
Duration
(
secs
)
*
time
.
Second
)
runtime
.
ReadMemStats
(
&
rtm
)
runtime
.
ReadMemStats
(
&
rtm
)
mem
:=
((
rtm
.
HeapIdle
-
rtm
.
HeapReleased
)
+
(
rtm
.
Alloc
+
rtm
.
HeapInuse
))
/
1e6
mem
:=
((
rtm
.
HeapIdle
-
rtm
.
HeapReleased
)
+
(
rtm
.
Alloc
+
rtm
.
HeapInuse
))
/
1e6
memMax
=
max
(
memMax
,
mem
)
memMax
=
max
(
memMax
,
mem
)
fmt
.
Printf
(
"Z
_
DEBUG: MEM: %v; MEM_MAX: %v; OBJ: %v, GO: %v, GC: %v
\n
"
,
fmt
.
Printf
(
"ZDEBUG: MEM: %v; MEM_MAX: %v; OBJ: %v, GO: %v, GC: %v
\n
"
,
mem
,
mem
,
memMax
,
memMax
,
(
rtm
.
Mallocs
-
rtm
.
Frees
)
/
1e3
,
(
rtm
.
Mallocs
-
rtm
.
Frees
)
/
1e3
,
...
...
zquit/pool.go
View file @
86d85eca
...
@@ -32,13 +32,13 @@ func (p *Pool) Add(z *ZQuit) {
...
@@ -32,13 +32,13 @@ func (p *Pool) Add(z *ZQuit) {
func
(
p
*
Pool
)
PrintStat
(
sec
int
)
{
func
(
p
*
Pool
)
PrintStat
(
sec
int
)
{
go
func
()
{
go
func
()
{
for
{
for
{
<-
time
.
After
(
time
.
Second
*
time
.
Duration
(
sec
))
time
.
Sleep
(
time
.
Second
*
time
.
Duration
(
sec
))
s
:=
""
s
:=
""
for
_
,
i
:=
range
p
.
items
{
for
_
,
i
:=
range
p
.
items
{
s
+=
i
.
GetStat
()
+
"; "
s
+=
i
.
GetStat
()
+
"; "
}
}
log
.
Printf
(
"Z
_
QUIT: %s"
,
s
)
log
.
Printf
(
"ZQUIT: %s"
,
s
)
}
}
}()
}()
}
}
...
...
zquit/zquit.go
View file @
86d85eca
...
@@ -101,8 +101,8 @@ func (q *ZQuit) GetStat() string {
...
@@ -101,8 +101,8 @@ func (q *ZQuit) GetStat() string {
func
(
q
*
ZQuit
)
PrintStat
(
sec
int
)
{
func
(
q
*
ZQuit
)
PrintStat
(
sec
int
)
{
go
func
()
{
go
func
()
{
for
{
for
{
<-
time
.
After
(
time
.
Second
*
time
.
Duration
(
sec
))
time
.
Sleep
(
time
.
Second
*
time
.
Duration
(
sec
))
log
.
Printf
(
"Z
_
QUIT: %s"
,
q
.
GetStat
())
log
.
Printf
(
"ZQUIT: %s"
,
q
.
GetStat
())
}
}
}()
}()
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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