简体   繁体   English

Web场中的Random()实例

[英]Random() instance in web farm

I'm running an application on multiple web servers that communicate with a distributed in-memory caching cluster, where I generate exclusive lock IDs on the application server -- the problem is that in high concurrency of parallel execution it is possible that more than one execution across all servers would generate the same pseudo random lock value. 我正在与分布式内存缓存群集进行通信的多个Web服务器上运行一个应用程序,在该服务器上我在应用程序服务器上生成了排他锁ID-问题是并行执行的高并发性可能会导致多个在所有服务器上执行将生成相同的伪随机锁定值。

The idea would be to initiate a single instance of the Random class per application pool using an incrementing seed within the distributed caching cluster, and to re-seed the randomizer after each helper method to generate a thread safe random number has reached a specific number of invocations. 想法是使用分布式缓存群集中的递增种子在每个应用程序池中启动Random类的单个实例,并在每种帮助程序方法生成线程安全随机数达到特定数量后重新设置随机化器的数量。调用。

Interested to see what thoughts you would have on this. 有兴趣了解您对此有何想法。

Random is just that - RANDOM. Random只是-随机。 Not guaranteed to be unique. 不保证唯一。 Rolling a die is an example of a random event, yet you may get the same result 6 out of 6 times. 掷骰子是随机事件的一个示例,但是您可能会在6次中获得6次相同的结果。

GUID objects are (almost) guaranteed to be unique, so just use those instead. GUID对象(几乎)保证是唯一的,因此只需使用它们即可。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM