I have developed a web application called Referral Program, It it developed by using PHP, MySQL. Users can joining the website and when they introduce new members, he/she gets a commission. The system working smoothly when the number of users is low. But the number of users over 50,000, then the system gets slows.
The problem is users comes into the system is like binary trees, and when he/she enter into the system, a commission is distributes up to top level(Root node or admin). A tree traversing is need to be done on each registration. It takes some more time. Five (or more) types of commissions must be given to each user register in the system, when 100,000 users in the system 500,000 records will be there. Then the system gets too slow. And 600-1000 users will be online. They can't do anything because the slow.
At last we consolidate the 500,000 records to 100,000 (we keep the sum only), the n its OK. They can use the application. We changed InnoDB to MyISAM, its faster but doesn't support transaction. But we should keep the original records. How it to be done ?
EDITED - 1
I am listing the server features here.
- Operating System : CentOS
- RAM : 25 GB
- Hard disc : 1500 GB
- Current Data Base size : 800 MB
- MySQL Version : 5.1 (or above)
- PHP : 5.3
MySQL error “Deadlock found when trying to get lock; try restarting transaction”
We are running a cron job (daily basis), it needs more time to complete because complex calculation is running in the huge database. When a user register or login to the system, then shows the above error. I just look here and here dealing with the same error, but i didn't get the exact solution. We are doing lot of SELECT / UPDATE / INSERT
EDITED - 2 This is the database structure I used, also other table are there, but I think it is not important now.
The function I used is here
public function getAllUplineId($id,$i,$position,$profile_field_id){
$select = "SELECT father_id
FROM 161_ft_individual
WHERE id=$id ";
$result = db_query($select);
while($node = db_fetch_object($result))
{
$user_id = $node->father_id;
if($user_id > 0)
{
$amount = 1;
$this->update_profile_value($user_id,$profile_field_id,$amount);
$i=$i+1;
$this->getAllUplineId($user_id,$i,$position,$profile_field_id);
}
}
}
public function update_profile_value($user_id,$profile_field_id,$amount){
$query = "UPDATE 161_ft_individual SET total_leg=total_leg+$amount
WHERE id='$user_id' LIMIT 1";
$result = db_query($query);
return $result;
}
The getAllUplineId() function takes and update all upline users from the point who register. The number of users more than 50,000 (in table 161_ft_individual
) it has become too slow and nobody can do anything. The table 161_leg_amount
has 500,000 records.
Thanks in advance.
SELECT
query supposed to be from 161_ft_individual ? If not, can you post the structure andSHOW CREATE TABLE ft_individual
output?