I got the following problem: When I try to increment one column of my mysql table the value get out of sync on high traffic loads.
The task is splited into two things incrementing the column and add a new row to another table. So if I add 100 rows the counter should stay at 100.
On high loads e.g. 100 request/s it comes to problems with the counter, I got 80 on the counter value but 120 rows are added.
//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();
I think the problem is that some request are handled faster then others and maybe override the values. Hope someone can help me with pointing me in the right direction or had a suggestion how to solve this problem.
Best, Nils