Hi all.
I'm trying to process CDR records (bill phone calls) using an AFTER INSERT trigger. I figured this is best than having a third party app do it each minute.
The sequence is as follows:
1) A phone call is finished and a new call record is inserted on table 1.
2) A trigger is fired AFTER inserting a row in table 1.
3) The trigger performs 5 select statements to bill the call and inserts the billed record on table 2.
4) The trigger updates the balance of the account owner of the call and finishes.
The biggest problem i´m seeing here is i will be billing at least 50 calls per second and i don´t know the exact behavior this will cause; since the balance of the account is being read before the process and updated afterwards.
My question is simple: If 50 cdrs are created in 1 second, will the fired triggers execute in parallel? or serialized?... This is vital, as if they execute in parallel the balance of the account may not be updated in order.
Out of the 5 queries performed to calculate the call, 2 of them are performed over a 40.000 row table holding the rates. This is taking 0.230 seconds per inner query, but the balance is updated at the very end of the script.
If two fired triggers start at the same time they will start processing the call with the same balance, and it will be useless.
Any toughts?
I'm trying to process CDR records (bill phone calls) using an AFTER INSERT trigger. I figured this is best than having a third party app do it each minute.
The sequence is as follows:
1) A phone call is finished and a new call record is inserted on table 1.
2) A trigger is fired AFTER inserting a row in table 1.
3) The trigger performs 5 select statements to bill the call and inserts the billed record on table 2.
4) The trigger updates the balance of the account owner of the call and finishes.
The biggest problem i´m seeing here is i will be billing at least 50 calls per second and i don´t know the exact behavior this will cause; since the balance of the account is being read before the process and updated afterwards.
My question is simple: If 50 cdrs are created in 1 second, will the fired triggers execute in parallel? or serialized?... This is vital, as if they execute in parallel the balance of the account may not be updated in order.
Out of the 5 queries performed to calculate the call, 2 of them are performed over a 40.000 row table holding the rates. This is taking 0.230 seconds per inner query, but the balance is updated at the very end of the script.
If two fired triggers start at the same time they will start processing the call with the same balance, and it will be useless.
Any toughts?