I'm writing a winform program with the following data model:
我正在用以下数据模型编写一个winform程序:
- The data structure is described by a set of class and subclass
- 数据结构由一组类和子类描述
- Once I store my data, I'm serializing the class to an XML file.
- 一旦我存储了数据,我就将类序列化为XML文件。
When the software is running the data must be accessed very fast (the data model is accessed between 50 and 60 per second.
当软件运行时,必须非常快地访问数据(数据模型每秒被访问50到60次)。
I plan to move the data storage from a XML file to an lite database.
我计划将数据存储从XML文件移动到lite数据库。
My question is the following: is it realistic to use a database not only for storage, but also during the program execution? Will I face loss of performance?
我的问题是:使用数据库不仅用于存储,而且在程序执行过程中也是如此吗?我将面临性能损失吗?
2 个解决方案
#1
2
If you don't need to update the data regularly, but just read from it, it would very probably be best to keep it in memory.
如果您不需要定期更新数据,而只是从数据中读取数据,那么最好将其保存在内存中。
We know little about your app, so we cannot really give much better advice here. Maybe in your case it would be enough to just keep the XML in an XPathDocument structure, so that you can perform fast searches using XPath queries.
我们对你的应用知之甚少,所以我们不能给出更好的建议。在您的示例中,仅将XML保持在XPathDocument结构中就足够了,这样您就可以使用XPath查询执行快速搜索。
Another option could be, if your data is mostly key/value pairs, that you read the XML into a Dictionary and then search that Dictionary in your app.
另一种选择是,如果您的数据主要是键/值对,那么您可以将XML读入字典,然后在应用程序中搜索该字典。
But reading from a database, even a light one, will hardly be faster. The only counter-case I can think of is a read-optimized fast NoSQL-DB such as MongoDB. But even then my money would be on an in-memory data structure optimized for searching.
但是从数据库中读取数据,即使是很轻的数据,也不会更快。我能想到的唯一的反例是一个读优化的快速NoSQL-DB,比如MongoDB。但即使这样,我的钱也会在内存中的数据结构上进行优化。
#2
1
If you need to access it that fast, I don't think that a database is a good alternative. There will always be latency involved in a database call, even if it is on the same machine. It can probably work sometimes, but there will be higher latency on some occasions that you cannot control
如果您需要如此快速地访问它,我认为数据库不是一个好的选择。即使数据库调用在同一台机器上,也始终存在延迟。它有时可能会工作,但在某些您无法控制的情况下会有更高的延迟
I think that you should keep the data in memory to have fast enough access.
我认为你应该把数据保存在内存中,以便有足够快的访问权限。
Why do you want to move away from XML? Do you have performance problems or other problems with the saving and loading of data?
为什么要远离XML?在保存和加载数据时,您是否存在性能问题或其他问题?
#1
2
If you don't need to update the data regularly, but just read from it, it would very probably be best to keep it in memory.
如果您不需要定期更新数据,而只是从数据中读取数据,那么最好将其保存在内存中。
We know little about your app, so we cannot really give much better advice here. Maybe in your case it would be enough to just keep the XML in an XPathDocument structure, so that you can perform fast searches using XPath queries.
我们对你的应用知之甚少,所以我们不能给出更好的建议。在您的示例中,仅将XML保持在XPathDocument结构中就足够了,这样您就可以使用XPath查询执行快速搜索。
Another option could be, if your data is mostly key/value pairs, that you read the XML into a Dictionary and then search that Dictionary in your app.
另一种选择是,如果您的数据主要是键/值对,那么您可以将XML读入字典,然后在应用程序中搜索该字典。
But reading from a database, even a light one, will hardly be faster. The only counter-case I can think of is a read-optimized fast NoSQL-DB such as MongoDB. But even then my money would be on an in-memory data structure optimized for searching.
但是从数据库中读取数据,即使是很轻的数据,也不会更快。我能想到的唯一的反例是一个读优化的快速NoSQL-DB,比如MongoDB。但即使这样,我的钱也会在内存中的数据结构上进行优化。
#2
1
If you need to access it that fast, I don't think that a database is a good alternative. There will always be latency involved in a database call, even if it is on the same machine. It can probably work sometimes, but there will be higher latency on some occasions that you cannot control
如果您需要如此快速地访问它,我认为数据库不是一个好的选择。即使数据库调用在同一台机器上,也始终存在延迟。它有时可能会工作,但在某些您无法控制的情况下会有更高的延迟
I think that you should keep the data in memory to have fast enough access.
我认为你应该把数据保存在内存中,以便有足够快的访问权限。
Why do you want to move away from XML? Do you have performance problems or other problems with the saving and loading of data?
为什么要远离XML?在保存和加载数据时,您是否存在性能问题或其他问题?