如果application server要scale,會遇到Optimistic concurrency control
使用的解法是在資料表上,有個欄位為version
執行時:
entry.Amount = entry.Amount + 50.000
err = globalDB.C("test").Update(bson.M{
"version": entry.Version,
"_id": entry.ID,
}, bson.M{"$set": map[string]interface{}{
"amount": entry.Amount,
"version": (entry.Version + 1),
}})
如果version沒有對應到,代表其他AS已經操作過這筆
再次利用vegeta
echo "GET http://localhost:3001" | vegeta attack -rate=100 -connections=1 -duration=1s | tee results.bin | vegeta report