Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
dkropachev committed May 30, 2024
1 parent 7f7905d commit fa12f33
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ package gocql

import (
"bufio"
"bytes"
"context"
"crypto/tls"
"encoding/gob"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -312,6 +314,7 @@ func (s *Session) dialWithoutObserver(ctx context.Context, host *HostInfo, cfg *
return nil, err
}

connMapSizeWatcher(c)
return c, nil
}

Expand Down Expand Up @@ -1878,3 +1881,24 @@ var (
ErrConnectionClosed = errors.New("gocql: connection closed waiting for response")
ErrNoStreams = errors.New("gocql: no streams available on connection")
)

func getRealSizeOf(v interface{}) int {
b := new(bytes.Buffer)
if err := gob.NewEncoder(b).Encode(v); err != nil {
return 0
}
return b.Len()
}

func connMapSizeWatcher(c *Conn) {
go func() {
for {
select {
case <-c.ctx.Done():
return
default:
println(c, "has calls size of ", getRealSizeOf(c.calls))
}
}
}()
}

0 comments on commit fa12f33

Please sign in to comment.