Commit 86d85eca authored by Vladimir Barsukov's avatar Vladimir Barsukov
Browse files

fix

parent 5b2da0e8
......@@ -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
......
......@@ -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,
......
......@@ -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)
}
}()
}
......
......@@ -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())
}
}()
}
......
Supports Markdown
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