简体   繁体   English

确保并发Web服务调用之间的数据一致性的最佳方法?

[英]Best performing way to guarantee data consistency between concurrent web service calls?

Multiple clients are concurrently accessing a JAX-JWS webservice running on Glassfish or some other application server. 多个客户端正在同时访问在Glassfish或某些其他应用程序服务器上运行的JAX-JWS Web服务。 Persistence is provided by something like Hibernate or OpenJPA. 持久性由Hibernate或OpenJPA之类的东西提供。 Database is Microsoft SQL Server 2005. 数据库是Microsoft SQL Server 2005。

The service takes a few input parameters, some "magic" occurs, and then returns what is basically a transformed version of the next available value in a sequence, with the particular sequence and transformation being determined by the inputs. 该服务采用一些输入参数,发生一些“魔术”,然后返回序列中下一个可用值的基本转换形式,具体的序列和转换由输入确定。 The "magic" that performs the transformation depends on the input parameters and various database tables (describing the relationship between the input parameters, the transformation, the sequence to get the next base value from, and the list of already served values for a particular sequence). 执行转换的“魔术”取决于输入参数和各种数据库表(描述输入参数,转换,从中获取下一个基值的序列以及特定序列已提供的值的列表之间的关系。 )。 Not sure if this could all be wrapped up in a stored procedure (probably), but also not sure if the client wants it there. 不知道这是否可以全部包装在存储过程中(可能),但也不确定客户端是否要在其中存储它。

What is the best way to ensure consistency (ie each value is unique and values are consumed in order, with no opportunity for a value to reach a client without also being stored in the database) while maintaining performance? 在保持性能的同时,确保一致性的最佳方法是什么(即每个值都是唯一的,并且按顺序使用值,而没有机会在不将其也存储在数据库中的情况下将其传递给客户)?

It's hard to provide a complete answer without a full description (table schemas, etc.), but giving my best guess here as to how it works, I would say that you need a transaction around your "magic", which marks the next value in the sequence as in use before returning it. 如果没有完整的描述(表模式等),很难提供完整的答案,但是在此最好地猜测它的工作方式,我想说您需要围绕“魔术”进行事务处理,这标志着下一个价值在返回之前按使用顺序进行操作。 If you want to reuse sequence numbers then you can later unflag them (for example, if the user then cancels what they're doing) or you can just consider them lost. 如果要重用序列号,则可以稍后取消标记它们(例如,如果用户随后取消了它们在做什么),或者可以认为它们已丢失。

One warning is that you want your transaction to be as short and as fast as possible, especially if this is a high-throughput system. 一个警告是您希望您的交易尽可能短且尽可能快,尤其是在这是一个高吞吐量的系统中。 Otherwise your sequence tables could quickly become a bottleneck. 否则,您的序列表可能很快成为瓶颈。 Analyze the process and see what the shortest transaction window is that will still allow you to ensure that a sequence isn't reused and use that. 分析该过程,看看最短的事务窗口是什么,仍然可以确保不重复使用序列并使用它。

It sounds like you have most of the elements you need here. 听起来您在这里拥有所需的大多数元素。 One thing that might pose difficulty, depending on how you've implemented your service, is that you don't want to write any response to the browser until your database transaction has been safely committed without errors. 根据您实现服务的方式,可能会造成困难的一件事是,您不希望在安全无误地安全提交数据库事务之前不向浏览器写入任何响应。

A lot of web frameworks keep the persistence session open (and uncommitted) until the response has been rendered to support lazy loading of persistent objects by the view. 许多Web框架都使持久性会话保持打开状态(并且未提交),直到呈现响应以支持通过视图延迟加载持久性对象为止。 If that's true in your case, you'll need to make sure that none of that rendered view is delivered to the client until you're sure it's committed. 如果您的情况是对的,则需要确保在确认提交之前,没有任何渲染视图交付给客户端。

One approach is a Servlet Filter that buffers output from the servlet or web service framework that you're using until it's completed its work. 一种方法是Servlet Filter ,该Filter会缓冲正在使用的Servlet或Web服务框架的输出,直到完成其工作为止。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对同一Web服务进行多个异步调用的最佳方法 - Best way to make multiple asynchronous calls to same web service 确保并发对象调用而不锁定的最佳方法是什么 - What is the best way to ensure concurrent object calls without locking 与直接数据库调用/RESTful 服务调用相比,对 Hazelcast 的数据检索速度进行基准测试的最佳方法是什么? - What is the best way to benchmark Hazelcast's speed to data retrieval, comparing with direct DB calls / RESTful service calls? Kony Web 应用程序在并发服务调用上有 Object.wait() - Kony Web Application is having Object.wait() on Concurrent Service Calls 春季:处理带有事务性数据库方法的长期Web服务调用的最佳方法? - Spring: Best way to handle long-running web-service calls with transactional DB methods? 对从Web服务获得的海量数据执行CRUD操作 - Performing CRUD operation on massive data attained from a Web-Service 保证回调始终是异步执行的最佳方法? - Best way to guarantee a callback is always executed asynchronously? 在Akka中安排一对外部服务呼叫的最佳方法 - Best way to sequence a pair of external service calls in Akka 设计Web服务的最佳方法,该服务必须将请求中的数据存储在列表或类似结构中 - Best way to design web service, which have to store data from requests in list or similar structure 如何在这种并发情况下确保数据一致性? - How do I ensure data consistency in this concurrent situation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM