ROM Gateways and sequel pools

Hi :slight_smile:

I’ve been using ROM in a multi-threaded app following the recommendation I found in one of the issues, this one: https://github.com/rom-rb/rom-sql/issues/309#issuecomment-384890852

Meaning, at the very beginning of my app (in the main thread), I do:
rom_base = new_config
rom_base.auto_registration

Then, at the workers, I call
rom_config = new_config
rom_config.register_relation(*rom_base.relation_classes)
container = ROM.container(rom_config)

However, I’m trying to understand how will that work regarding the underlying sequel connection pool. If I understand this well, it will create one gateway per container (And thus, one sequel connection pool per gateway?)

I understand this well, it will create one gateway per container (And thus, one sequel connection pool per gateway?)

Your understanding is correct :slightly_smiling_face:

And is there a way to reuse the pool? Or should I be dimensioning the pool differently for ROM, taking into consideration that I will have one connection per thread anyway?

I have been looking for some answers about this subject. could you please provide more answers @solnic?

When using Puma web server for example how can i configure rom so its used by the workers ?

@renatolond you can pass in a sequel connection object right into the rom configuration via ROM::Configuration.new(:sql, your_sequel_connection).

There’s nothing special you need to do, but remember to disconnect on_worker_boot. See this SO question.