Skip to content

Commit

Permalink
add warning log for ring buffer collision
Browse files Browse the repository at this point in the history
  • Loading branch information
negrel committed Mar 21, 2024
1 parent 100cb6e commit a108ac6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
default = pkgs.buildGoModule {
pname = "prisme";
version = "0.11.0";
vendorHash = "sha256-ZztZLzkKDhka9kZRSThccP+hcQH9qD5xY5rIRhm+H3A=";
vendorHash = "sha256-ozHf3CAdR9rwhpckEz8aA2wDXFOfmvM3IUBK1Ez3fJs=";

src = ./.;
# Skip go test.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/golang-migrate/migrate/v4 v4.17.0
github.com/google/uuid v1.5.0
github.com/google/wire v0.5.0
github.com/negrel/ringo v0.3.0
github.com/negrel/ringo v0.5.0
github.com/oschwald/maxminddb-golang v1.12.0
github.com/rs/zerolog v1.31.0
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/negrel/ringo v0.3.0 h1:LtSdWHCOR1AjIE5welBJb96rMtx0kifCHw3RuaWt2e4=
github.com/negrel/ringo v0.3.0/go.mod h1:cDSDvU1fY2PcKCOj0OB53CBqSt1m1uKWUqcIJlaCvL4=
github.com/negrel/ringo v0.5.0 h1:o29JXp+aWN5b8o+2U40JhXUXx7FVHnQ3O66h9E8RKgw=
github.com/negrel/ringo v0.5.0/go.mod h1:cDSDvU1fY2PcKCOj0OB53CBqSt1m1uKWUqcIJlaCvL4=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0-rc5 h1:Ygwkfw9bpDvs+c9E34SdgGOj41dX/cbdlwvlWt0pnFI=
Expand Down
15 changes: 12 additions & 3 deletions pkg/services/eventstore/clickhouse_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,27 @@ import (
// ProvideClickhouseService is a wire provider for a clickhouse based event
// storage service.
func ProvideClickhouseService(ch clickhouse.Ch, logger zerolog.Logger) Service {

service := &ClickhouseService{
logger: logger,
conn: ch.Conn,
maxBatchSize: config.ParseUintEnvOrDefault("PRISME_EVENTSTORE_MAX_BATCH_SIZE", 4096, 64),
maxBatchTimeout: config.ParseDurationEnvOrDefault("PRISME_EVENTSTORE_MAX_BATCH_TIMEOUT", 1*time.Minute),
}
service.pageViewRingBuf = ringo.NewWaiter(
ringo.NewManyToOne[*event.PageView](int(service.maxBatchSize * 10)),
ringo.NewManyToOne(
int(service.maxBatchSize*10),
ringo.WithManyToOneCollisionHandler[*event.PageView](ringo.CollisionHandlerFunc(func(_ any) {
service.logger.Warn().Msg("pageview events ring buffer collision detected, consider increasing PRISME_EVENTSTORE_MAX_BATCH_SIZE")
})),
),
)
service.customEventRingBuf = ringo.NewWaiter(
ringo.NewManyToOne[*event.Custom](int(service.maxBatchSize * 10)),
ringo.NewManyToOne(
int(service.maxBatchSize*10),
ringo.WithManyToOneCollisionHandler[*event.Custom](ringo.CollisionHandlerFunc(func(_ any) {
service.logger.Warn().Msg("custom events ring buffer collision detected, consider increasing PRISME_EVENTSTORE_MAX_BATCH_SIZE")
})),
),
)

logger = logger.With().
Expand Down

0 comments on commit a108ac6

Please sign in to comment.