开发者

Slowdown identified: ReaderWriterLock(-1). May I use different locks?

after hours of tracking mysterious one or two seconds long l开发者_高级运维asting "freeze" I finally found out that its ReaderWriterLock(-1). It is server app and the lock here is held for writing to client collection. Im not familiar with locking so I would like to ask if there is not any better/faster way? How about using lock object to lock add/read statements of collection? This freeze occurs very randomly but its very annoying since it causes lag to all connected clients. Thanks!


Do you mean AcquireReaderLock(-1)/AcquireWriterLock(-1) or similar? That would suggest that the lock is contended - in which case, fix whichever code is holding the (write) lock at the time. If the delay is literally with the locking class, then maybe ReaderWriterLockSlim would have less overhead. lock would indeed be simpler still (hence cheaper), but doesn't allow the same granularity - it is essentially a mutex lock, so only one thread can play with the object. Contrast a reader/writer lock which allows one writer NAND multiple readers.

To be honest, it sounds as simple as "occasionally, some code will take a write lock (blocking other callers), and take a while to complete". Finding the offending code is a black art, but has little to do with the lock itself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜