Skip to content

Commit 183cbf0

Browse files
authored
Merge pull request #404 from florianl/flo-bytes-buffer
Improve CPU utilization by reducing allocation overhead
2 parents afbea5b + b013e75 commit 183cbf0

File tree

5 files changed

+5
-182
lines changed

5 files changed

+5
-182
lines changed

bootstrap.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import (
1515
"sync/atomic"
1616
"time"
1717

18-
"github.com/ClickHouse/clickhouse-go/lib/leakypool"
19-
2018
"github.com/ClickHouse/clickhouse-go/lib/binary"
2119
"github.com/ClickHouse/clickhouse-go/lib/data"
2220
"github.com/ClickHouse/clickhouse-go/lib/protocol"
@@ -100,7 +98,6 @@ func open(dsn string) (*clickhouse, error) {
10098
readTimeout = DefaultReadTimeout
10199
writeTimeout = DefaultWriteTimeout
102100
connOpenStrategy = connOpenRandom
103-
poolSize = 100
104101
)
105102
if len(database) == 0 {
106103
database = DefaultDatabase
@@ -134,12 +131,6 @@ func open(dsn string) (*clickhouse, error) {
134131
if size, err := strconv.ParseInt(query.Get("block_size"), 10, 64); err == nil {
135132
blockSize = int(size)
136133
}
137-
if size, err := strconv.ParseInt(query.Get("pool_size"), 10, 64); err == nil {
138-
poolSize = int(size)
139-
}
140-
poolInit.Do(func() {
141-
leakypool.InitBytePool(poolSize)
142-
})
143134
if altHosts := strings.Split(query.Get("alt_hosts"), ","); len(altHosts) != 0 {
144135
for _, host := range altHosts {
145136
if len(host) != 0 {

lib/data/block.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package data
22

33
import (
4+
"bytes"
45
"database/sql/driver"
56
"fmt"
67
"io"
@@ -9,7 +10,6 @@ import (
910

1011
"github.com/ClickHouse/clickhouse-go/lib/binary"
1112
"github.com/ClickHouse/clickhouse-go/lib/column"
12-
wb "github.com/ClickHouse/clickhouse-go/lib/writebuffer"
1313
)
1414

1515
type offset [][]int
@@ -165,8 +165,8 @@ func (block *Block) Reserve() {
165165
block.offsets = make([]offset, len(block.Columns))
166166
for i := 0; i < len(block.Columns); i++ {
167167
var (
168-
offsetBuffer = wb.New(wb.InitialSize)
169-
columnBuffer = wb.New(wb.InitialSize)
168+
offsetBuffer = new(bytes.Buffer)
169+
columnBuffer = new(bytes.Buffer)
170170
)
171171
block.buffers[i] = &buffer{
172172
Offset: binary.NewEncoder(offsetBuffer),
@@ -289,8 +289,8 @@ func (info *blockInfo) write(encoder *binary.Encoder) error {
289289
type buffer struct {
290290
Offset *binary.Encoder
291291
Column *binary.Encoder
292-
offsetBuffer *wb.WriteBuffer
293-
columnBuffer *wb.WriteBuffer
292+
offsetBuffer *bytes.Buffer
293+
columnBuffer *bytes.Buffer
294294
}
295295

296296
func (buf *buffer) WriteTo(w io.Writer) (int64, error) {

lib/leakypool/leaky_pool.go

Lines changed: 0 additions & 23 deletions
This file was deleted.

lib/writebuffer/buffer.go

Lines changed: 0 additions & 120 deletions
This file was deleted.

lib/writebuffer/buffer_test.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)