Skip to content

Commit 23be4a5

Browse files
guergaboGabriel Guerradfarr
authored
feat(postgres): add postgres query config + db query optimizations (#320) (#321)
* feat(postgres): add query + tick fixes * feat(postgres): conditional prepare statement * fix(postgres): Ranging over a map is non deterministic * Lazily define prepared statement --------- Co-authored-by: Gabriel Guerra <[email protected]> Co-authored-by: David Farr <[email protected]>
1 parent cc44852 commit 23be4a5

File tree

5 files changed

+432
-302
lines changed

5 files changed

+432
-302
lines changed

cmd/dst/run.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ func RunDSTCmd() *cobra.Command {
146146
system.AddOnRequest(t_api.ReleaseLock, coroutines.ReleaseLock)
147147
system.AddOnRequest(t_api.ClaimTask, coroutines.ClaimTask)
148148
system.AddOnRequest(t_api.CompleteTask, coroutines.CompleteTask)
149-
system.AddOnTick(2, coroutines.EnqueueTasks)
150-
system.AddOnTick(2, coroutines.TimeoutLocks)
151-
system.AddOnTick(2, coroutines.SchedulePromises)
152-
system.AddOnTick(2, coroutines.TimeoutPromises)
153-
system.AddOnTick(10, coroutines.NotifySubscriptions)
149+
system.AddOnTick(1000, coroutines.EnqueueTasks)
150+
system.AddOnTick(1000, coroutines.TimeoutLocks)
151+
system.AddOnTick(1000, coroutines.SchedulePromises)
152+
system.AddOnTick(1000, coroutines.TimeoutPromises)
153+
system.AddOnTick(1000, coroutines.NotifySubscriptions)
154154

155155
reqs := []t_api.Kind{
156156
// PROMISE
@@ -247,6 +247,7 @@ func RunDSTCmd() *cobra.Command {
247247
cmd.Flags().String("aio-store-postgres-username", "", "postgres username")
248248
cmd.Flags().String("aio-store-postgres-password", "", "postgres password")
249249
cmd.Flags().String("aio-store-postgres-database", "resonate_dst", "postgres database name")
250+
cmd.Flags().StringToString("aio-store-postgres-query", make(map[string]string, 0), "postgres query options")
250251
cmd.Flags().Duration("aio-store-postgres-tx-timeout", 2*time.Second, "postgres transaction timeout")
251252
cmd.Flags().Float32("aio-network-success-rate", 0.5, "simulated success rate of http requests")
252253
cmd.Flags().Float32("aio-queuing-success-rate", 0.5, "simulated success rate of queuing requests")
@@ -261,6 +262,7 @@ func RunDSTCmd() *cobra.Command {
261262
_ = viper.BindPFlag("dst.aio.subsystems.store.config.postgres.username", cmd.Flags().Lookup("aio-store-postgres-username"))
262263
_ = viper.BindPFlag("dst.aio.subsystems.store.config.postgres.password", cmd.Flags().Lookup("aio-store-postgres-password"))
263264
_ = viper.BindPFlag("dst.aio.subsystems.store.config.postgres.database", cmd.Flags().Lookup("aio-store-postgres-database"))
265+
_ = viper.BindPFlag("aio.subsystems.store.config.postgres.query", cmd.Flags().Lookup("aio-store-postgres-query"))
264266
_ = viper.BindPFlag("dst.aio.subsystems.store.config.postgres.txTimeout", cmd.Flags().Lookup("aio-store-postgres-tx-timeout"))
265267
_ = viper.BindPFlag("dst.aio.subsystems.networkDST.config.p", cmd.Flags().Lookup("aio-network-success-rate"))
266268
_ = viper.BindPFlag("dst.aio.subsystems.queuingDST.config.p", cmd.Flags().Lookup("aio-queuing-success-rate"))

cmd/serve/serve.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ func ServeCmd() *cobra.Command {
108108
system.AddOnRequest(t_api.ReleaseLock, coroutines.ReleaseLock)
109109
system.AddOnRequest(t_api.ClaimTask, coroutines.ClaimTask)
110110
system.AddOnRequest(t_api.CompleteTask, coroutines.CompleteTask)
111-
system.AddOnTick(2, coroutines.EnqueueTasks)
112-
system.AddOnTick(2, coroutines.TimeoutLocks)
113-
system.AddOnTick(2, coroutines.SchedulePromises)
114-
system.AddOnTick(2, coroutines.TimeoutPromises)
115-
system.AddOnTick(1, coroutines.NotifySubscriptions)
111+
system.AddOnTick(1000, coroutines.EnqueueTasks)
112+
system.AddOnTick(1000, coroutines.TimeoutLocks)
113+
system.AddOnTick(1000, coroutines.SchedulePromises)
114+
system.AddOnTick(1000, coroutines.TimeoutPromises)
115+
system.AddOnTick(1000, coroutines.NotifySubscriptions)
116116

117117
// metrics server
118118
mux := netHttp.NewServeMux()
@@ -205,14 +205,15 @@ func ServeCmd() *cobra.Command {
205205
cmd.Flags().Int("aio-store-workers", 1, "number of concurrent connections to the store")
206206
cmd.Flags().Int("aio-store-batch-size", 100, "max submissions processed each tick by a store worker")
207207
cmd.Flags().String("aio-store-sqlite-path", "resonate.db", "sqlite database path")
208-
cmd.Flags().Duration("aio-store-sqlite-tx-timeout", 250*time.Millisecond, "sqlite transaction timeout")
208+
cmd.Flags().Duration("aio-store-sqlite-tx-timeout", 10_000*time.Millisecond, "sqlite transaction timeout")
209209
cmd.Flags().Bool("aio-store-sqlite-reset", false, "sqlite database clean on shutdown")
210210
cmd.Flags().String("aio-store-postgres-host", "localhost", "postgres host")
211211
cmd.Flags().String("aio-store-postgres-port", "5432", "postgres port")
212212
cmd.Flags().String("aio-store-postgres-username", "", "postgres username")
213213
cmd.Flags().String("aio-store-postgres-password", "", "postgres password")
214214
cmd.Flags().String("aio-store-postgres-database", "resonate", "postgres database name")
215-
cmd.Flags().Duration("aio-store-postgres-tx-timeout", 250*time.Millisecond, "postgres transaction timeout")
215+
cmd.Flags().StringToString("aio-store-postgres-query", make(map[string]string, 0), "postgres query options")
216+
cmd.Flags().Duration("aio-store-postgres-tx-timeout", 10_000*time.Millisecond, "postgres transaction timeout")
216217
cmd.Flags().Bool("aio-store-postgres-reset", false, "postgres database clean on shutdown")
217218
// Network
218219
cmd.Flags().Int("aio-network-size", 100, "size of network submission queue buffered channel")
@@ -242,6 +243,7 @@ func ServeCmd() *cobra.Command {
242243
_ = viper.BindPFlag("aio.subsystems.store.config.postgres.password", cmd.Flags().Lookup("aio-store-postgres-password"))
243244
_ = viper.BindPFlag("aio.subsystems.store.config.postgres.database", cmd.Flags().Lookup("aio-store-postgres-database"))
244245
_ = viper.BindPFlag("aio.subsystems.store.config.postgres.database", cmd.Flags().Lookup("aio-store-postgres-database"))
246+
_ = viper.BindPFlag("aio.subsystems.store.config.postgres.query", cmd.Flags().Lookup("aio-store-postgres-query"))
245247
_ = viper.BindPFlag("aio.subsystems.store.config.postgres.txTimeout", cmd.Flags().Lookup("aio-store-postgres-tx-timeout"))
246248
_ = viper.BindPFlag("aio.subsystems.store.config.postgres.reset", cmd.Flags().Lookup("aio-store-postgres-reset"))
247249
// Network

0 commit comments

Comments
 (0)