Cross Process (and machine) Synchronization (Semaphores)

北城以北 提交于 2020-07-09 06:10:29

问题


Background:

My WCF application has to call a service that does not have any concurrency checking in it. It is a service created by a third party and getting them to add concurrency checking may not be possible.

I can ensure that the only way to call the third party service is via my WCF application. So I am considering putting concurrency checking in my code.

To do this, I will use an identifier that uniquely describes the data being modified. The idea is that if one call to the service is modifying data related to the identifier, then other calls for that identifier will need to wait till it is done.

The Problem:

My WCF Service is load balanced. I can have as many as 16 instances running at the same time, all on different virtual machines.

So most of the .NET classes that deal with synchronization assume a shared memory space.

Are there standard, "best practice" type ways to do synchronization for load balanced instances of services?

I have considered using a database table (SQL Server) to try to manage this, but seems wrong from an architectural point of view to use my persistence layer for this purpose. I am hoping for another solution.

Summary:

How do I do synchronization (Locks, Mutex, Semaphore, etc) across machines? (Preferably without using database tables to manage it.)


回答1:


Use a Distributed lock manager to lock resource modification based on the identifier you created.

Some of DLM's you can use are:

  • zookeeper
  • Redis
  • DistributedLock
  • DistributedLocking


来源:https://stackoverflow.com/questions/52010860/cross-process-and-machine-synchronization-semaphores

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!