I'm building a web service that needs to consult a ~80mb file and perform a lookup (and some simple math of two of the columns) using user-submitted data and return results. The file looks like this:
1 236 comment
236 13255 comment
....
The incoming request includes a number, and I need to find which row contains the range (column 1, column 2) that hold that number, and return the comment.
My first thought was to try loading the file and reading it on every request. This slows down the connection significantly and leads to a 2-3 second page load.
My second idea was to load the file into memory once for each worker (using Flask and Gunicorn). This DDOS'ed my cloud instance and consumed way too much memory. I'm sure there's a more memory efficient way that doesn't require purchasing more resources.
I was thinking of potentially writing a small local web service that would respond to queries on the loopback interface. This shouldn't be too slow (web API request that doesn't leave the box), but adds some complexity.
Is there something simple I'm missing or have overlooked? Is there a design pattern I'm not familiar with that would help?