实时数据Web应用程序设计

发布于 2024-10-01 04:04:52 字数 772 浏览 1 评论 0原文

我即将开始设计一个个人项目的架构,该项目具有以下特征:

  1. 本质上是一个包含多个基于一项运动的并发用户的“游戏”。
  2. 这项运动的比赛会定期进行模拟,并将结果存储在数据库中。
  3. 用户可以在模拟比赛发生时“实时”查看其详细信息,也可以在比赛发生后查看结果。

我开发了一个类似的 Web 应用程序,其范围比该项目的上一个迭代小得多。然而,在这种情况下,我选择使用 SQLite 作为我的数据库提供程序,因为我还有一个可再发行的桌面应用程序,可用于手动模拟比赛(事实上,它作为 Web 应用程序外部的独立模拟器运行)。我的限制现在已转变为仅是 Web 应用程序,因此我不必担心这种额外的复杂性。

我之前的实现的主要问题是处理并发请求。我犯了一个错误,即使用一个数据库(由磁盘上的单个文件表示)来支持模拟方面(在服务器上的单独进程中运行)和 Web 应用程序。因此,当用户在进行实时模拟的同时访问网站时,会出现各种数据库访问问题,因为它被一个进程锁定。我通过在数据库操作上实现跨进程互斥体解决了这个问题,但这极大地降低了网站的性能。

我将使用的工具是:

  1. 用于 Web 应用程序的 ASP.NET。
  2. 用于数据库的 SQL Server 2008 R2...可能带有用于对象关系映射的 NHibernate 层。

我的问题是,如何设计才能实现最佳效率和并发访问?显然,从文件转移到实际的数据库服务器会有其好处,但我是否需要两台冗余服务器——一台用于模拟过程,一台用于 Web 服务器过程?

任何建议将不胜感激!

谢谢。

I'm about to begin designing the architecture of a personal project that has the following characteristics:

  1. Essentially a "game" containing several concurrent users based on a sport.
  2. Matches in this sport are simulated on a regular basis and their results stored in a database.
  3. 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:

  1. ASP.NET for the web application.
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

×纯※雪 2024-10-08 04:04:52

您应该可以在同一个数据库上执行这两项操作。并发访问是现代数据库引擎的设计目的。并发读取通常完全没有问题;并发写入会锁定尽可能少的数据(一个表,甚至只是一些行),而不是整个数据库。

不过,您应该记住一些事情:

  • 明智地使用交易。一方面,事务是确保数据库始终一致的重要工具 - 简而言之,事务要么完全发生,要么根本不发生。另一方面,两个并发事务可能会导致死锁,并且这些错误可能非常难以调试。
  • 规范化并使用约束来保护数据完整性。强制执行外键可以挽救局面,尽管它通常会导致更麻烦的管理。
  • 最大限度地减少花在数据访问上的时间:不需要时不要保留连接,绝对确保没有泄漏任何连接,不要获取您知道不需要的数据,尽可能多地执行在 SQL 中而不是在代码中进行与数据相关的处理(尤其是可以使用联接、子查询、分组、视图等解决的问题)

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:

  • Use transactions wisely. On the one hand, a transaction is an important tool in making sure your database is always consistent - in short, a transaction either happens completely, or not at all. On the other hand, two concurrent transactions can cause deadlocks, and those buggers can be extremely hard to debug.
  • Normalize, and use constraints to protect your data integrity. Enforcing foreign keys can save the day, even though it often leads to more cumbersome administration.
  • Minimize the amount of time spent on data access: don't keep connections around when you don't need them, make absolutely sure you're not leaking any connections, don't fetch data you know don't need, do as much data-related processing (especially things that can be solved using joins, subqueries, groupings, views, etc.) in SQL instead of in code
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文