实时数据Web应用程序设计
我即将开始设计一个个人项目的架构,该项目具有以下特征:
- 本质上是一个包含多个基于一项运动的并发用户的“游戏”。
- 这项运动的比赛会定期进行模拟,并将结果存储在数据库中。
- 用户可以在模拟比赛发生时“实时”查看其详细信息,也可以在比赛发生后查看结果。
我开发了一个类似的 Web 应用程序,其范围比该项目的上一个迭代小得多。然而,在这种情况下,我选择使用 SQLite 作为我的数据库提供程序,因为我还有一个可再发行的桌面应用程序,可用于手动模拟比赛(事实上,它作为 Web 应用程序外部的独立模拟器运行)。我的限制现在已转变为仅是 Web 应用程序,因此我不必担心这种额外的复杂性。
我之前的实现的主要问题是处理并发请求。我犯了一个错误,即使用一个数据库(由磁盘上的单个文件表示)来支持模拟方面(在服务器上的单独进程中运行)和 Web 应用程序。因此,当用户在进行实时模拟的同时访问网站时,会出现各种数据库访问问题,因为它被一个进程锁定。我通过在数据库操作上实现跨进程互斥体解决了这个问题,但这极大地降低了网站的性能。
我将使用的工具是:
- 用于 Web 应用程序的 ASP.NET。
- 用于数据库的 SQL Server 2008 R2...可能带有用于对象关系映射的 NHibernate 层。
我的问题是,如何设计才能实现最佳效率和并发访问?显然,从文件转移到实际的数据库服务器会有其好处,但我是否需要两台冗余服务器——一台用于模拟过程,一台用于 Web 服务器过程?
任何建议将不胜感激!
谢谢。
I'm about to begin designing the architecture of a personal project that has the following characteristics:
- Essentially a "game" containing several concurrent users based on a sport.
- Matches in this sport are simulated on a regular basis and their results stored in a database.
- Users can view the details of a simulated match "live" when it is occurring as well as see results after they have occurred.
I developed a similar web application with a much smaller scope as the previous iteration of this project. In that case, however, I chose to go with SQLite as my DB provider since I also had a redistributable desktop application that could be used to manually simulate matches (and in fact that ran as a standalone simulator outside of the web application). My constraints have now shifted to be only a web application, so I don't have to worry about this additional level of complexity.
My main problem with my previous implementation was handling concurrent requests. I made the mistake of using one database (which was represented by a single file on disk) to power both the simulation aspect (which ran in a separate process on the server) and the web application. Hence, when users were accessing the website concurrently with a live simulation happening, there were all sorts of database access issues since it was getting locked by one process. I fixed this by implementing a cross-process mutex on database operations but this drastically slowed down the performance of the website.
The tools I will be using are:
- ASP.NET for the web application.
- SQL Server 2008 R2 for the database... probably with an NHibernate layer for object relational mapping.
My question is, how do I design this so I will achieve optimal efficiency as well as concurrent access? Obviously shifting to an actual DB server from a file will have it's positives, but do I need to have two redundant servers--one for the simulation process and one for the web server process?
Any suggestions would be appreciated!
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该可以在同一个数据库上执行这两项操作。并发访问是现代数据库引擎的设计目的。并发读取通常完全没有问题;并发写入会锁定尽可能少的数据(一个表,甚至只是一些行),而不是整个数据库。
不过,您应该记住一些事情:
You should be fine doing both on the same database. Concurrent access is what modern database engines are designed for. Concurrent reads are usually no problem at all; concurrent writes lock the minimum possible amount of data (a table, or even just a number of rows), not the entire database.
A few things you should keep in mind though: