I am developing a web service with Erlang. Low latency is the goal. The service provides several views on a set of files. Building these representations takes time, since I have to read in files, analyze them as CSVs, store their fields in records, etc.
A naive approach would be to re-read these files and make the necessary conversions for each request, so that the web application is completely stateless. But I'm concerned about the delay.
Another approach would be to create a server (implementing the gen_server
behavior) that prepares these views at startup and stores them in memory as LoopData
, and then returns the views as needed to web workers. But this reduces concurrency, as this server processes one request at a time.
Is there a design pattern in Erlang that supports costly initialization at startup and yet allows simultaneous access to initialized data? (The key is that this data is immutable, so I am not interested in mutual exclusion.)
source share