node.js 数据结构 volatile/when 是在数据结构上使用数据库吗?
Are node.js data structures volatile/when to use a database over data structure?
我正在考虑使用 node.js 构建类似 API 的服务,但我无法理解是使用数据结构还是将信息存储在 database/text 文件中。
基本上,该程序将允许用户上网并收集该用户的地理编码位置。然后该服务将该信息存储在 javascript 数据结构中或将其存储到数据库或文本文件中。然后另一个用户会登录,我会将他们与接近他们的用户联系起来。
我的问题是,如果我有一个数据结构(某种基于地理代码的自定义实现的排序列表),所有这些信息都是易变的吗?如果程序崩溃,我会丢失它吗?
即使访问和写入该信息需要更长的时间,将信息存储在文本文件或数据库中是否更可取?
此外,如果我使用的是数据结构方法,如果我需要扩展到更多服务器,这是否会使扩展应用程序变得更加困难?
有什么想法吗?
My question is, if I have a datastructure (some sort of custom
implemented sorted list based off of geo-codes) would all of that
information be volatile and I would loose it if the program crashed?
是的,它会不稳定,如果程序崩溃你就会丢失它。所有 Javascript 数据都保存在 RAM 中。
Would it be more preferable to store the information in a text file or
database even though the access and write of that information would
take longer?
何时将数据保存到持久存储在很大程度上取决于具体情况。你可以只有一个磁盘存储,或者你可以有一个定期存储到磁盘的 RAM 存储,或者你可以有一个组合(持久存储前面的 RAM 缓存)。使用数据库通常会为您做很多缓存。
Also, if I was using the data structure approach, would that make it
more difficult to scale the application if I needed to expand to
additional servers?
如果您想在多个服务器之间共享实时数据存储,那么您必须使用存储在 node.js 内存中的 Javascript 数据以外的其他东西。通常的解决方案是使用某种外部数据库,它本身可以是内存中的(如 Redis)或磁盘存储(如 Mongo 或 Couchbase),然后所有不同的服务器都可以访问这些数据库。
我正在考虑使用 node.js 构建类似 API 的服务,但我无法理解是使用数据结构还是将信息存储在 database/text 文件中。
基本上,该程序将允许用户上网并收集该用户的地理编码位置。然后该服务将该信息存储在 javascript 数据结构中或将其存储到数据库或文本文件中。然后另一个用户会登录,我会将他们与接近他们的用户联系起来。
我的问题是,如果我有一个数据结构(某种基于地理代码的自定义实现的排序列表),所有这些信息都是易变的吗?如果程序崩溃,我会丢失它吗?
即使访问和写入该信息需要更长的时间,将信息存储在文本文件或数据库中是否更可取?
此外,如果我使用的是数据结构方法,如果我需要扩展到更多服务器,这是否会使扩展应用程序变得更加困难?
有什么想法吗?
My question is, if I have a datastructure (some sort of custom implemented sorted list based off of geo-codes) would all of that information be volatile and I would loose it if the program crashed?
是的,它会不稳定,如果程序崩溃你就会丢失它。所有 Javascript 数据都保存在 RAM 中。
Would it be more preferable to store the information in a text file or database even though the access and write of that information would take longer?
何时将数据保存到持久存储在很大程度上取决于具体情况。你可以只有一个磁盘存储,或者你可以有一个定期存储到磁盘的 RAM 存储,或者你可以有一个组合(持久存储前面的 RAM 缓存)。使用数据库通常会为您做很多缓存。
Also, if I was using the data structure approach, would that make it more difficult to scale the application if I needed to expand to additional servers?
如果您想在多个服务器之间共享实时数据存储,那么您必须使用存储在 node.js 内存中的 Javascript 数据以外的其他东西。通常的解决方案是使用某种外部数据库,它本身可以是内存中的(如 Redis)或磁盘存储(如 Mongo 或 Couchbase),然后所有不同的服务器都可以访问这些数据库。