Robin Westerlundh
Robin Westerlundh

Reputation: 196

Holding a big map in memory or do multiple sql calls?

I am coming from a background of web development but now am building my first server application in Go and have some questions.

The application will get a lot of http requests containing a string that I need to lookup and validate, basically if the string exists in database it is valid.

Normally I do a new SQL query at every incoming http request, but are there better to just do one big SQL request at init and load all the 50.000 strings into a map in memory? And use that for fast lookup?

Upvotes: 1

Views: 173

Answers (1)

thwd
thwd

Reputation: 24848

It depends on the string size and the amount of strings.

If they fit in memory just fine go for memory mapping them, else query the DB.

PS: This is not really a question, neither does it have a definitive answer.

Upvotes: 3

Related Questions