Predicted transactions

When you put something into a dynamic array, it won't grow by just 1 when reaching the limit.  This is important because changing size is an expensive operation.

 

For example if I have a job to execute, and the input data just keep coming and coming every now and then.

 

There could be 2 models for this: 

 

Solution #1: Keep a timeout for the job, extend the execution time by fixed time(such as 1s)  every time we received a new job. When timeout is reached, execute the job. 

When a new input come, and there's no existing job available, we simple create a new job

 

Solution #2: Keep a timeout for the tob, before execution, collect new inputs, before execution in the last second, mark it as silent period. If we have new input coming in the silent period, do not execute the job, request another spin of time as the timeout is defined.

 

你可能感兴趣的:(transaction)