Skip to content

Commit

Permalink
perf: use chpool again
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Jan 13, 2024
1 parent 9006555 commit 6d69639
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions internal/chstorage/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ func (c *dialingClickhouseClient) Do(ctx context.Context, q ch.Query) error {
}()
return db.Do(ctx, q)
}

// TODO: rewrite or disable
var _ = NewDialingClickhouseClient
11 changes: 10 additions & 1 deletion internal/chstorage/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/ClickHouse/ch-go"
"github.com/ClickHouse/ch-go/chpool"
"github.com/cenkalti/backoff/v4"
"github.com/go-faster/errors"
"github.com/go-faster/sdk/zctx"
Expand Down Expand Up @@ -83,7 +84,15 @@ func Dial(ctx context.Context, dsn string, opts DialOptions) (ClickhouseClient,
connectBackoff.MaxElapsedTime = time.Minute
return backoff.RetryNotifyWithData(
func() (ClickhouseClient, error) {
client := NewDialingClickhouseClient(chOpts)
client, err := chpool.Dial(ctx, chpool.Options{
ClientOptions: chOpts,
HealthCheckPeriod: time.Second,
MaxConnIdleTime: time.Second * 10,
MaxConnLifetime: time.Minute,
})
if err != nil {
return nil, errors.Wrap(err, "dial")
}
if err := client.Ping(ctx); err != nil {
return nil, errors.Wrap(err, "ping")
}
Expand Down

0 comments on commit 6d69639

Please sign in to comment.