Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmarks for "insert many" operations #591

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 53 additions & 6 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ func (c *clientWithSimpleStop[TTx]) Stop() {
_ = c.Client.Stop(context.Background())
}

func newTestConfig(t *testing.T, callback callbackFunc) *Config {
t.Helper()
func newTestConfig(tb testing.TB, callback callbackFunc) *Config {
tb.Helper()
workers := NewWorkers()
if callback != nil {
AddWorker(workers, &callbackWorker{fn: callback})
Expand All @@ -126,7 +126,7 @@ func newTestConfig(t *testing.T, callback callbackFunc) *Config {
return &Config{
FetchCooldown: 20 * time.Millisecond,
FetchPollInterval: 50 * time.Millisecond,
Logger: riversharedtest.Logger(t),
Logger: riversharedtest.Logger(tb),
MaxAttempts: MaxAttemptsDefault,
Queues: map[string]QueueConfig{QueueDefault: {MaxWorkers: 50}},
TestOnly: true, // disables staggered start in maintenance services
Expand All @@ -136,11 +136,11 @@ func newTestConfig(t *testing.T, callback callbackFunc) *Config {
}
}

func newTestClient(t *testing.T, dbPool *pgxpool.Pool, config *Config) *Client[pgx.Tx] {
t.Helper()
func newTestClient(tb testing.TB, dbPool *pgxpool.Pool, config *Config) *Client[pgx.Tx] {
tb.Helper()

client, err := NewClient(riverpgxv5.New(dbPool), config)
require.NoError(t, err)
require.NoError(tb, err)

return client
}
Expand Down Expand Up @@ -5495,3 +5495,50 @@ func TestDefaultClientIDWithHost(t *testing.T) {
require.Equal(t, strings.Repeat("a", 60)+"_2024_03_07T04_39_12_123456", defaultClientIDWithHost(startedAt, strings.Repeat("a", 60)))
require.Equal(t, strings.Repeat("a", 60)+"_2024_03_07T04_39_12_123456", defaultClientIDWithHost(startedAt, strings.Repeat("a", 61)))
}

func BenchmarkClient(b *testing.B) {
ctx := context.Background()

type testBundle struct{}

setup := func(b *testing.B) (*Client[pgx.Tx], *testBundle) {
b.Helper()

dbPool := riverinternaltest.TestDB(ctx, b)
config := newTestConfig(b, nil)

return newTestClient(b, dbPool, config), &testBundle{}
}

b.Run("JobInsertMany", func(b *testing.B) {
client, _ := setup(b)

params := make([]InsertManyParams, 100)
for i := range params {
params[i].Args = noOpArgs{}
}

b.ResetTimer()

for i := 0; i < b.N; i++ {
_, err := client.InsertMany(ctx, params)
require.NoError(b, err)
}
})

b.Run("JobInsertManyFast", func(b *testing.B) {
client, _ := setup(b)

params := make([]InsertManyParams, 100)
for i := range params {
params[i].Args = noOpArgs{}
}

b.ResetTimer()

for i := 0; i < b.N; i++ {
_, err := client.InsertManyFast(ctx, params)
require.NoError(b, err)
}
})
}
Loading