我有一箇中央數據庫用於處理用戶信用與多個服務器讀取和寫入它。該應用程序坐落在這些服務器之上做每個請求的下列服務用戶請求:樂觀鎖定用戶信用管理
1. check if user has enough credit for the task by reading from db. 2. perform the time consuming request 3. deduct a credit from user account, save the new credit count back to db.
應用程序使用的數據庫的樂觀鎖定。所以,以下可能發生
1. request a comes in, see that user x has enough credit, 2. request b comes in, see that user x has enough credit, 3. a performs work 4. a saves the new credit count back to db 5. b performs work 6. b tries to save the new credit count back to db, application gets an exception and fails to account for this credit deduction.
有了悲觀鎖定,應用程序將需要顯式地獲取鎖定的用戶帳戶,以保證獨佔訪問,但由於該系統有許多併發請求該殺死的性能。
那麼這個信用系統會是一個很好的新設計?
「執行耗時的請求」涉及到數據庫活動嗎?如果是這樣,是否需要將需要撤消的事情更改爲數據庫? – 2015-03-30 04:16:28
@Rick James:不,「執行耗時的請求不執行數據庫活動」 – user121196 2015-03-31 01:56:47