全网数据同步

发布于 2024-12-16 02:43:35 字数 1193 浏览 4 评论 0原文

我们开发了一个在 MS SQL Server 上运行的 C# WinForms 应用程序。直到今天,我们仍在使用一个非常简单的自制 OR-Mapper(使用反射)以及通过单例模式实现的廉价缓存机制。有一个用户触发的“重置”功能。该架构是一个简单的两层(客户端、服务器)三层(客户端上的表示和逻辑,服务器上的 MS SQL 作为数据层)。

通常,我们加载大约 300 行和大约 30 列,这些列经常更改(以及其他一些很少更改的表)。此应用程序的不同实例在不同的客户端计算机上运行,​​加载了相同的 300 行,并且正在更改随机行上的数据。应用程序立即更新数据库上的数据。在这样做之前,会检查完整性,以便用户在出现问题时得到反馈。但对于用户在屏幕上看到旧值的某些行,当他想要确保拥有最新数据时,他必须手动重置缓存。

如果应用程序考虑更改的行本身,那就太好了。每隔几秒就有更新。但其中只有一些更新与其他应用程序相关(取决于活动过滤器...)

我想到的解决方案:

  1. 使用带有公共缓存的 OR-Mapper(例如带有集群缓存的 NHibernate)
    • 悬而未决的问题:这些二级缓存是为客户端应用程序设计的吗?当缓存发生更改时,我可以触发 UI 更新吗?其他基于 OR-Mapper 的解决方案?
  2. 使用应用程序服务器实现另一层,将逻辑移动到该应用程序服务器。仅运行一个实例,该实例缓存数据并在逻辑对象上发送事件,通知其他客户端更新的数据。不要在客户端上缓存任何数据。
  3. 添加某种逻辑级别的数据更改通知(基于广播的通知...)
    • 未决问题:现有库?在 SQL Server 上加载?
  4. 完全其他的解决方案?

我知道我在这里没有得到解决方案。只需要一些关于这些解决方案(或新解决方案)的想法...感谢您的任何意见!

We have developed an C# WinForms application running on a MS SQL Server. Until today we are using a very simple self-made OR-Mapper (using Reflection) with a cheap caching mechanism implemented with a singleton pattern. There's a user triggered "reset" function. The architecture is a simple two tier (client, server) three layers (presentation and logic on the client, MS SQL as data tier on the server).

Typically we load about 300 rows with about 30 columns, which are changing quite often (and some other tables which change rarely). Different instances of this application are running on different client computers have the same 300 rows loaded and are changing data on a random row. The application update the data immediately on the database. Before they do so, the integrity are checked so the user get's a feedback if something is wrong. But for some of the rows the user sees old values on the screen, he has to manually reset the cache when he wants to be sure having up-to-date data.

It would be nice if the applications consider the changed rows itself. There are updates every few seconds. But only some of these updates are relevant for the other applications (depending on the active filter...)

Solutions which I have in mind:

  1. Using a OR-Mapper with a common cache (e.g. NHibernate with a clustered cache)
    • Open questions: Are these L2 caches made for client apps? Can I trigger UI updates when cache changes happen? Other OR-Mapper based solutions?
  2. Implementing another tier using an application server, moving logic to this application server. Run only one instance, which caches the data and sends events on the Logic Object's which notify the other clients of updated data. Don't cache any data on the clients.
  3. Add some kind of data changes notifications on the logic level (broadcast based noticiation...)
    • Open questions: Existing libraries? Load on SQL Server?
  4. Completly other solution?

I'm aware that I don't get the solution here. Just need some thoughts about these solution (or new ones)... Thanks for any inputs!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

秋风の叶未落 2024-12-23 02:43:35

我想在这里分享我的经验。在类似的情况下,所有客户端都在一个公司 LAN 上。我在我的客户端应用程序中实现了一个 UDP 客户端(发送方/接收方),每当客户端更新数据时,它就会在网络广播地址上广播“DataRefreshMessage”。所有其他客户端在收到“DataRefreshMessage”时更新其视图。

我知道 UDP 不可靠,但对于我的要求来说足够可靠,并且我的解决方案工作得很好。

i would like to share my experience here.In similar scenario where all clients were on a single corporate LAN. I implemented a UDP client(sender/receiver) in my client application that broadcasted "DataRefreshMessage" on Network BroadCast address whenever a client updated the data.and all other clients updated their views upon receiving the "DataRefreshMessage".

I am aware that UDP is not reliable but was reliable enough for my requirements and my solution is working perfectly fine.

羅雙樹 2024-12-23 02:43:35

我自己没有使用过这个,但我相信 SQL Server 有 当先前查询的数据发生更改时,可以通知您的应用程序的依赖功能

不过,我不知道这与订阅这些通知的应用程序数量的关系如何。我链接的该页面上有一条注释,说这种方法并非旨在供大量客户使用。

I have not used this myself, but I believe that SQL Server has dependency functionality that can notify your application when changes are made to previously queried data.

I don't know how well that scales with the number of applications that are subscribing to those notifications, though. There is a note on that page that I linked saying that this approach was not designed to be used by large numbers of clients.

彩扇题诗 2024-12-23 02:43:35

老实说,在我看来,你就像是小题大做了。如果您只加载 300 条记录,只需经常从数据库重新加载数据,而不用担心缓存。数据集是如此之小,无论如何它都会非常快,并且您不会因为使用分布式缓存等而遇到额外的复杂性和故障点。

如果您需要确保只有一个人写入数据库,并且该人何时写入最新的数据。您可以实现某种数据库锁定表,并在执行此操作之前检查其他人是否正在写入。

Honestly, it sounds to me like you are making a mountain out of a mole hill. if you are just loading 300 records just reload the data from the database every so often and don't bother with caching. The data set is so small its going to be really fast anyway and you wont have the additional complexity and points of failure of using a distributed cache and all that.

If you need to be sure that only one person writes to the database, and when that person writes its the most recent data. You could implement some sort of database lock table, and check if someone else is writing before you do so.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文