我遇到了以下问题:当我尝试增加 mysql 表的一列时,值在高流量负载时不同步。
该任务分为两件事,增加列并将新行添加到另一个表。所以如果我添加 100 行,计数器应该保持在 100。
在高负载(例如 100 请求/秒)时,计数器出现问题,我在计数器值上得到 80,但添加了 120 行。
//This is the current increment routine build with an Yii ActiveRecord Class
$id = 123;
$dataRow = ActiveRecordModel::model()->findByPK($id);
$dataRow->counter +=1;
$dataRow->save();
//Add the row
$row = new ActiveRecordModelRow();
$row->operatingSystem = 1;
$row->save();
我认为问题在于某些请求的处理速度比其他请求更快,并且可能会覆盖这些值。希望有人可以帮助我指出正确的方向,或者对如何解决这个问题提出建议。
最好的,尼尔斯