Skip to content

Commit 4005976

Browse files
authored
Fix performance and tests (#46)
1 parent 7e5d73c commit 4005976

8 files changed

Lines changed: 301 additions & 23 deletions

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ up:
22
docker compose up -d
33

44
test:
5-
go test -timeout=30m ./...
5+
go test -timeout=10m ./...
66

77
test_v:
88
go test -v ./...
99

1010
test_short:
11-
go test ./... -short
11+
go test -short ./...
1212

1313
test_race:
14-
go test ./... -short -race
14+
go test -short -race ./...
1515

1616
test_stress:
1717

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
mysql:
66
image: mysql:8.0
77
restart: unless-stopped
8-
command: [ "--max_connections=50000" ]
8+
command: [ "--max_connections=5000" ]
99
ports:
1010
- 3306:3306
1111
environment:
@@ -15,7 +15,7 @@ services:
1515
postgres:
1616
image: postgres:15.3
1717
restart: unless-stopped
18-
command: postgres -c 'max_connections=50000'
18+
command: postgres -c 'max_connections=5000'
1919
ports:
2020
- 5432:5432
2121
environment:

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ toolchain go1.24.1
77
require (
88
github.com/ThreeDotsLabs/watermill v1.4.0-rc.2
99
github.com/go-sql-driver/mysql v1.4.1
10-
github.com/jackc/pgx/v5 v5.7.2
10+
github.com/jackc/pgx/v5 v5.7.5
1111
github.com/lib/pq v1.10.9
1212
github.com/oklog/ulid v1.3.1
1313
github.com/pkg/errors v0.9.1
@@ -27,9 +27,9 @@ require (
2727
github.com/pmezard/go-difflib v1.0.0 // indirect
2828
github.com/rogpeppe/go-internal v1.13.1 // indirect
2929
github.com/sony/gobreaker v1.0.0 // indirect
30-
golang.org/x/crypto v0.35.0 // indirect
31-
golang.org/x/sync v0.11.0 // indirect
32-
golang.org/x/text v0.22.0 // indirect
30+
golang.org/x/crypto v0.37.0 // indirect
31+
golang.org/x/sync v0.13.0 // indirect
32+
golang.org/x/text v0.24.0 // indirect
3333
google.golang.org/appengine v1.6.7 // indirect
3434
gopkg.in/yaml.v3 v3.0.1 // indirect
3535
)

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI
2020
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
2121
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
2222
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
23-
github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI=
24-
github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=
23+
github.com/jackc/pgx/v5 v5.7.5 h1:JHGfMnQY+IEtGM63d+NGMjoRpysB2JBwDr5fsngwmJs=
24+
github.com/jackc/pgx/v5 v5.7.5/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
2525
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
2626
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
2727
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
@@ -48,16 +48,16 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
4848
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
4949
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
5050
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
51-
golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs=
52-
golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
51+
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
52+
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
5353
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
54-
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
55-
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
54+
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
55+
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
5656
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
5757
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
5858
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
59-
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
60-
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
59+
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
60+
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
6161
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
6262
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
6363
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=

pkg/sql/pubsub_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ func TestDefaultPostgreSQLSchema_planner_mis_estimate_regression(t *testing.T) {
753753
require.NoError(t, err)
754754

755755
messagesCount := 100_000
756-
if testing.Short() {
756+
if testing.Short() || os.Getenv("CI") == "true" {
757757
messagesCount = 1_000
758758
}
759759
tests.AddSimpleMessagesParallel(t, messagesCount, pub, topicName, 50)

pkg/sql/queue_schema_adapter_postgresql_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestPostgreSQLQueueSchemaAdapter(t *testing.T) {
6161
case msg := <-messages:
6262
receivedMessages = append(receivedMessages, msg)
6363
msg.Ack()
64-
case <-time.After(100 * time.Millisecond):
64+
case <-time.After(5 * time.Second):
6565
t.Errorf("expected to receive message")
6666
break
6767
}

pkg/sql/schema_adapter_postgresql.go

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (s DefaultPostgreSQLSchema) SelectQuery(params SelectQueryParams) (Query, e
180180
` + nextOffsetQuery.Query + `
181181
)
182182
183-
SELECT "offset", transaction_id::text, uuid, payload, metadata FROM ` + s.MessagesTable(params.Topic) + `
183+
SELECT "offset", transaction_id, uuid, payload, metadata FROM ` + s.MessagesTable(params.Topic) + `
184184
185185
WHERE
186186
(
@@ -269,23 +269,59 @@ func (x *XID8) Scan(src interface{}) error {
269269
return errors.New("cannot scan nil value into XID8")
270270
}
271271

272+
// We want to support scanning from various types (different drivers, like lib/pq, pgx, etc.)
272273
switch v := src.(type) {
274+
case int64:
275+
if v < 0 {
276+
return fmt.Errorf("cannot convert negative int64 %d to XID8", v)
277+
}
278+
*x = XID8(uint64(v))
279+
return nil
280+
281+
case uint64:
282+
*x = XID8(v)
283+
return nil
284+
285+
case int32:
286+
if v < 0 {
287+
return fmt.Errorf("cannot convert negative int32 %d to XID8", v)
288+
}
289+
*x = XID8(uint64(v))
290+
return nil
291+
292+
case uint32:
293+
*x = XID8(v)
294+
return nil
295+
296+
// pgx
273297
case string:
298+
if v == "" {
299+
*x = 0
300+
return nil
301+
}
274302
val, err := strconv.ParseUint(v, 10, 64)
275303
if err != nil {
276-
return err
304+
return fmt.Errorf("cannot parse string %q as uint64: %w", v, err)
277305
}
278306
*x = XID8(val)
279307
return nil
308+
309+
// lib/pq
280310
case []byte:
311+
if len(v) == 0 {
312+
*x = 0
313+
return nil
314+
}
315+
281316
val, err := strconv.ParseUint(string(v), 10, 64)
282317
if err != nil {
283-
return err
318+
return fmt.Errorf("cannot parse bytes %q as uint64: %w", string(v), err)
284319
}
285320
*x = XID8(val)
286321
return nil
322+
287323
default:
288-
return errors.New("unsupported Scan value type for XID8")
324+
return fmt.Errorf("cannot scan %T into XID8", src)
289325
}
290326
}
291327

0 commit comments

Comments
 (0)