如何设计一个多用户的Ajax Web应用程序能够同时安全多用户、应用程序、安全、Web

2023-09-10 15:54:40 作者:比钻石还耀眼的男人ヽ

我有一个网页,显示从服务器大量数据。通信是通过AJAX实现。

I have a web page that shows a large amount of data from the server. The communication is done via ajax.

每当用户交互,并改变这些数据(说用户A重命名的东西),它告诉服务器做的动作和服务器返回新更改的数据。

Every time the user interacts and changes this data (Say user A renames something) it tells the server to do the action and the server returns the new changed data.

如果用户B访问,同时该页面并创建一个新的数据对象,将通过AJAX再次告诉服务器,服务器将与该用户的新对象返回。

If user B accesses the page at the same time and creates a new data object it will again tell the server via ajax and the server will return with the new object for the user.

在A的页面上,我们有一个重命名的对象的数据。而在B的页面,我们有一个新的对象数据。在服务器中的数据既具有重命名的对象和一个新的对象。

On A's page we have the data with a renamed object. And on B's page we have the data with a new object. On the server the data has both a renamed object and a new object.

我有哪些选择与服务器保持网页同步,当多个用户同时使用它?

What are my options for keeping the page in sync with the server when multiple users are using it concurrently?

选项,如锁定整个页面或倾倒整个状态到用户的每一个变化都比较回避。

Such options as locking the entire page or dumping the entire state to the user on every change are rather avoided.

如果有帮助,在该具体示例网页调用运行在数据库上存储的过程的静态的webmethod。该存储过程将返回已更改的任何数据,并没有更多的。静态的WebMethod随后转发该存储过程的返回给客户端。

If it helps, in this specific example the webpage calls a static webmethod that runs a stored procedure on the database. The stored procedure will return any data it has changed and no more. The static webmethod then forwards the return of the stored procedure to the client.

赏金编辑:

如何设计一个多用户的Web应用程序,它使用Ajax与服务器进行通信,但避免了问题并发?

How do you design a multi-user web application which uses Ajax to communicate with the server but avoids problems with concurrency?

即。并发访问的功能和数据上的数据库没有数据或状态损坏的危险

I.e. concurrent access to functionality and to data on a database without any risk of data or state corruption

推荐答案

概述:

简介 服务器架构 客户端架构 在更新的情况下 提交案例 在冲突情况下 在性能和放大器;可扩展性

Raynos

我将不讨论任何特定的产品在这里。什么其他人所说是一个很好的工具集来看看已经(也许添加的node.js到列表)。

I will not discuss any particular product here. What others mentioned is a good toolset to have a look at already (maybe add node.js to that list).

从体系结构的角度来看,你似乎可以在版本控制软件中看到了同样的问题。在改变到一个目的一个用户的检查,另一个用户想要改变在另一种方式=>冲突相同的对象。你必须整合用户的更改,而在同一时间能够传递更新及时有效,检测和解决像上面的冲突的对象

From an architectural viewpoint, you seem to have the same problem that can be seen in version control software. One user checks in a change to an object, another user wants to alter the same object in another way => conflict. You have to integrate users changes to objects while at the same time being able to deliver updates timely and efficiently, detecting and resolving conflicts like the one above.

如果我是你的鞋子我会制定这样的:

If I was in your shoes I would develop something like this:

确定一个合理的水平上,你会定义我称之为原子神器(网页?网页上的对象?里面的物品价值?)。这将取决于你的网络服务器,数据库和放大器;缓存硬件,#的用户,#对象等不是一件容易的决定。

Determine a reasonable level at which you would define what I'd call "atomic artifacts" (the page? Objects on the page? Values inside objects?). This will depend on your webservers, database & caching hardware, # of user, # of objects, etc. Not an easy decision to make.

对于每个原子的工件有:

For each atomic artifact have:

应用程序范围内唯一ID 在递增版本号 锁定机制写访问(互斥也许) 小史或更新日志一ringbuffer内(共享内存可以很好地用于那些)。单个键值对可能也没关系虽然少了扩展。看http://en.wikipedia.org/wiki/Circular_buffer

一个服务器或虚拟服务器的组件,能够有效地提供的相关的更新日志到连接的用户。观察者模式是你的朋友这一点。

A server or pseudo-server component that is able to deliver relevant changelogs to a connected user efficiently. Observer-Pattern is your friend for this.

一个JavaScript客户端,能够有一个长期运行的HTTP连接到上述服务器上面,或者使用轻量级轮询。 前端 Web技术的演化史

A javascript client that is able to have a long-running HTTP-Connection to said server above, or uses lightweight polling.

一个JavaScript的神器更新组件,刷新该网站的内容时,连接变化看文物,历史的JavaScript客户端通知。 (又是一个观察者模式可能是一个不错的选择)

A javascript artifact-updater component that refreshes the sites content when the connected javascript client notifies of changes in the watched artifacts-history. (again an observer pattern might be a good choice)

一个JavaScript神器的提交组件,可以请求改变原子的神器,尝试获取互斥锁。它会检测工件的状态已经由其他用户之前,只需几秒钟改变(JavaScript客户端的latancy和提交过程的因素),通过比较知名客户方神器版本-id和当前的服务器端的神器版本ID。

A javascript artifact-committer component that may request to change an atomic artifact, trying to acquire mutex lock. It will detect if the state of the artifact had been changed by another user just seconds before (latancy of javascript client and commit process factors in) by comparing known clientside artifact-version-id and current serverside artifact-version-id.

一个JavaScript的冲突解算器允许一个人而改变,是最正确的决定。你可能不希望只是告诉用户有人比你快,我删除了自己的变化。去哭了。从技术性比较强的不同之处或更人性化的解决方案,许多方案似乎不可能。

A javascript conflict-solver allowing for a human which-change-is-the-right decision. You may not want to just tell the user "Someone was faster than you. I deleted your change. Go cry.". Many options from rather technical diffs or more user-friendly solutions seem possible.

那么,如何将它推出...

So how would it roll ...

在浏览器呈现页 的javascript看到的工件,每个具有至少一个字段的值,unique-和一个版本标识 在JavaScript客户端被启动,请求观看发现的历史文物从发现开始的版本(较老的变化是不感兴趣) 在服务器进程注意到请求,并不断检查和/或发送历史 历史条目可包含简单的通知神器x将发生变化,客户端请请求数据,允许客户自主查询或完整的数据集神器x将变为值福 JavaScript的神器更新程序所能,尽快为他们成为已知有更新,获取新的值。它执行新的Ajax请求,或得到由JavaScript客户端feeded。 DOM的内容被更新的页面,用户可任选通知。历史观赏继续。 人工物提交者知道从用户输入所需的新值,并发送变更请求到服务器 在获取服务器端互斥 服务器收到嘿,我知道,从123版本神器X的状态,让我将它设置为值FOO请。 如果在Serverside集团神器版本的x等于(不能小于)123的新值被接受,124新版本ID生成的。 在新的状态信息更新到版本124和可选的新的价值富都投入在了神器X的ringbuffer的开始(更新日志/历史记录) 在服务器端的互斥锁的释放 在请求神器提交者乐于接受提交,确认与新的ID。 同时服务器端的服务器组件不断轮询/推ringbuffers到连接的客户端。所有观看神器x的缓冲区的客户将获得在自己平时的延迟新的状态信息和价值(见案例1)。 工件的提交者都知道期望从用户输入新的值并发送一个变更请求到服务器 在同时另一个用户成功更新同一工件(见案例2),但由于种种延迟,这是未知的,以我们的其他用户。 在这样一个服务器端的互斥体被收购(或等待,直到更快用户提交自己的变化) 服务器收到嘿,我知道,从123版本神器X的状态,让我将它设置为价值富。 在Serverside集团神器X版本,现在是124了。提出请求的客户端无法知道他会被覆盖的值。 显然,服务器已经拒绝变更请求(不包括在神干预覆盖的优先级),释放互斥体,是一种足以发回新的版本-id和新的价值,直接到客户端。 在面临着一个拒绝提交请求和价值的变化,请求用户还不知道,JavaScript的神器提交者是指在冲突解决它显示并解释这个问题给用户。 用户,psented有一些选择由智能冲突解析JS是$ P $,被允许再次试图更改值。 一旦选择他认为合适的一个值的用户,这个过程开始了从案例2(或3的情况下,如果别人是快,再次) 在轮询创建请求,每秒,每秒5,不管你认为是一个可以接受的等待时间。这可以是相当残酷的,以你的基础设施,如果你不配置(Apache的?)和(PHP的?)不够好,是轻量级的首发。理想的是优化在服务器端的轮询请求,使得它运行比轮询间隔的长度的时间少得多。分裂的运行时间的一半很可能意味着高达50%,降低整个系统的负载, 在通过HTTP推送(假设webworkers太离谱,以支持他们)会要求你有一个阿帕奇/ lighthttpd过程可用于每个用户的所有时间。保留这些工艺和系统的驻留内存的总内存将是一个非常特定的规模限制,你会遇到。降低了连接的内存占用将是必要的,以及限制量连续的CPU和I / O工作在每个这些进行(要大量的睡眠/空闲时间) Polling creates requests, one per second, 5 per second, whatever you regard as an acceptable latency. This can be rather cruel to your infrastructure if you do not configure your (Apache?) and (php?) well enough to be "lightweight" starters. It is desirable to optimize the polling request on the serverside so that it runs for far less time than the length of the polling interval. Splitting that runtime in half might well mean lowering your whole system load by up to 50%, Pushing via HTTP (assuming webworkers are too far off to support them) will require you to have one apache/lighthttpd process available for each user all the time. The resident memory reserved for each of these processes and your systems total memory will be one very certain scaling limit that you will encounter. Reducing the memory footprint of the connection will be necessary, as well as limiting the amount continuous CPU and I/O work done in each of these (you want lots of sleep/idle time) 忘记的数据库和文件系统,你会的需要的对于经常查询某种基于共享内存的后端(如果客户端不直接轮询然后每个正在运行的服务器进程将) 如果你去的memcache,你可以更好地扩展,但它仍然是昂贵的 的互斥提交了,即使你想拥有多台前端服务器LOADBALANCE工作globaly。 Forget database and filesystem, you will need some sort of shared memory based backend for the frequent polling (if the client does not poll directly then each running server process will) if you go for memcache you can scale better, but its still expensive The mutex for commits has to work globaly even if you want to have multiple frontend servers to loadbalance. 不管你是轮询或接收推,试图获得的信息都看了文物一步。 如果客户端轮询,许多用户往往观看相同的文物,你可以尝试发布这些文物为静态文件的历史记录,允许Apache缓存它,但它刷新在服务器端,当工件改变。这需要PHP / memcache的出局一定的要求。 Lighthttpd是柠efficent在提供静态文件。 使用像cotendo.com内容分发网络推神器历史上。推延迟会比较大,但可扩展性是一个梦想 在写(不使用HTTP)的用户连接到使用java或flash(?)一个真正的服务器。你必须处理为许多用户在一个服务器线程。骑自行车,开插座,这样做(或委托)所需的工作。通过分叉过程或启动更多的服务器可扩展。互斥体必须保持globaly独特的虽然。 将神器id范围根据负载情况下组的frontend-和后端服务器。这将允许更好地使用的持久性存储器(没有数据库具有的所有数据),并使得能够以大规模的mutexing。你的JavaScript必须保持在同一时间连接到多台服务器,但。

嗯,我希望这会是一个开始为自己的想法。我相信有很多更多的可能性。 我更欢迎任何批评或改进这个帖子​​,维基已启用。

Well I hope this can be a start for your own ideas. I am sure there are plenty more possibilities. I am more than welcoming any criticism or enhancements to this post, wiki is enabled.

克里斯托夫Strasen

Christoph Strasen