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
Hide whitespace changes
Inline
Side-by-side
zdb/pool.go
View file @
86d85eca
...
...
@@ -2,7 +2,6 @@ package zdb
import
(
"context"
"errors"
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
"log"
...
...
@@ -86,13 +85,22 @@ func (d *Pool) WithContext(ctx context.Context) *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
)
}
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
)
}
...
...
@@ -113,7 +121,7 @@ func (d *Pool) NewConn(mode connMode, pgConnString string) error {
q
.
Index
=
len
(
d
.
SrvAsync
)
d
.
SrvAsync
=
append
(
d
.
SrvAsync
,
q
)
default
:
return
errors
.
New
(
"unknown mode"
)
panic
(
"unknown mode"
)
}
return
err
...
...
zdebug/zdebug.go
View file @
86d85eca
...
...
@@ -14,14 +14,14 @@ func NewMonitor(secs int) {
var
memMax
uint64
for
{
<-
time
.
After
(
time
.
Duration
(
secs
)
*
time
.
Second
)
time
.
Sleep
(
time
.
Duration
(
secs
)
*
time
.
Second
)
runtime
.
ReadMemStats
(
&
rtm
)
mem
:=
((
rtm
.
HeapIdle
-
rtm
.
HeapReleased
)
+
(
rtm
.
Alloc
+
rtm
.
HeapInuse
))
/
1e6
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
,
memMax
,
(
rtm
.
Mallocs
-
rtm
.
Frees
)
/
1e3
,
...
...
zquit/pool.go
View file @
86d85eca
...
...
@@ -32,13 +32,13 @@ func (p *Pool) Add(z *ZQuit) {
func
(
p
*
Pool
)
PrintStat
(
sec
int
)
{
go
func
()
{
for
{
<-
time
.
After
(
time
.
Second
*
time
.
Duration
(
sec
))
time
.
Sleep
(
time
.
Second
*
time
.
Duration
(
sec
))
s
:=
""
for
_
,
i
:=
range
p
.
items
{
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 {
func
(
q
*
ZQuit
)
PrintStat
(
sec
int
)
{
go
func
()
{
for
{
<-
time
.
After
(
time
.
Second
*
time
.
Duration
(
sec
))
log
.
Printf
(
"Z
_
QUIT: %s"
,
q
.
GetStat
())
time
.
Sleep
(
time
.
Second
*
time
.
Duration
(
sec
))
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