简体   繁体   English

带有Node.js的Mysql:让Node.js一直都在数据库中保存/加载内容有意义吗?

[英]Mysql with Node.js: Does it make sense to have node.js save/load stuff to/from the database all the time?

So I have a small game in node.js(only the server of course) which has map data and player accounts stored in a mysql database. 因此,我在node.js(当然只有服务器)中有一个小游戏,该游戏的地图数据和玩家帐户存储在mysql数据库中。 Right now I constructed it in a way that minimizes the amount of queries made by loading data from the database and keeping it in javascript objects/arrays or whatever seems appropriate and only writing to the database when needed. 现在,我以一种方式来构造它,以最大程度地减少通过从数据库加载数据并将其保存在javascript对象/数组或任何合适的东西中而仅在需要时才写入数据库的查询量。

Now I was thinking: Is this really worth it? 现在我在想:这真的值得吗? In many cases it would be alot better(in terms of data would be more save and WAY more up-to-date) to hardly store data in the server and just loading it from the database when needed(respectively writing when it needs to be changed). 在许多情况下,最好不要将数据存储在服务器中,而仅在需要时从数据库中加载(分别在需要时写入),这样会更好(就数据而言,可以节省更多时间,并且可以获取最新信息)。更改)。

My question is: Is it efficient/save/recommendable to have the server read/write from the database often rather than having data from the database in javascript variables in the server? 我的问题是:让服务器经常从数据库中进行读写操作,而不是使服务器中的javascript变量中具有来自数据库的数据,这是否高效/节省/推荐?

Additional info: 附加信息:
-The nodejs server and my mysql server are on the same machine and a query usually takes less than 1ms or maybe 3ms for big queries like loading room data. -nodejs服务器和我的mysql服务器位于同一台机器上,对于大的查询(如加载房间数据),查询通常少于1毫秒或3毫秒。
-I am using a module simply called mysql . -我正在使用一个简单地称为mysql的模块。
-If needed I will include extra info, just ask in a comment. -如果需要,我将提供其他信息,只需在评论中提出即可。

Really depends on your Use-Case. 确实取决于您的用例。 Generally speaking, I would not add another layer of caching in node.js but handle that in your db with a bigger cache and optimized queries. 一般来说,我不会在node.js中添加另一层缓存,而是通过更大的缓存和优化的查询在您的数据库中进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM