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

fix

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