在内存中保存一个大地图还是进行多次SQL调用?

huangapple go评论68阅读模式
英文:

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

问题

我来自Web开发背景,但现在正在使用Go构建我的第一个服务器应用程序,并有一些问题。

该应用程序将接收许多包含字符串的HTTP请求,我需要查找和验证这些字符串,基本上如果字符串存在于数据库中,则为有效。

通常,我会在每个传入的HTTP请求中执行一个新的SQL查询,但是否有更好的方法可以在初始化时执行一个大的SQL请求,并将所有的50,000个字符串加载到内存中的映射中?然后使用该映射进行快速查找?

英文:

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?

答案1

得分: 3

这取决于字符串的大小和字符串的数量。

如果它们可以很好地适应内存,就使用内存映射,否则查询数据库。

PS:这不是一个真正的go问题,也没有一个确定的答案。

英文:

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 [tag:go] question, neither does it have a definitive answer.

huangapple
  • 本文由 发表于 2013年2月19日 16:44:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/14953190.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定