Need tips on how to achieve a thread-safe queue in fs2 (Scala)

371 Views Asked by At

I need to implement a microservice that loads a ton of data into memory at startup and makes that data available via HTTP GET. I have been looking at fs2 as an option to make the data available to the web layer via an fs2.Queue.

My concern is that if I use the synchronous queue from fs2, my performance of serving the data might be affected negatively because of the blocking nature of the synchronous queue (on enqueue operation).

Is this a valid concern? Also, which Queue abstractions (in fs2) are thread-safe? ie: can I pass any Queue around to multiple threads and can they all safely take items out of the queue without more than one of them taking the same element out of the queue?

EDIT: Use case: 10Mil records served by the Stream -> many workers (threads) picking work from the Stream via a HTTP endpoint (GET)

0

There are 0 best solutions below