Tested with Python 3.8.10 and Ubuntu 20.04.
Check Python version:
$ python3 --version
Python 3.8.10
Run test cases:
python3 test-cases.py
Run with debug output and 10x faster:
PYFCA_DEBUG=1 python3 test-cases.py 0.1
pts.py demonstrates the correctness of the algorithm.
The input sequence for the test is a list of dictionaries, each containing an
id key which matches the order of the item in the sequence.
The transformation consists of two functions:
- the first one returns immediately for inputs with even
idbut has a delay for inputs with oddid, - the second one is synchronous and returns immediately.
The soft limit for number of items processed in parallel is 4.
To perform the test, run:
PYFCA_DEBUG=1 python3 pts.py
The following happens:
- Six items are written.
- First 3 writes resolve immediately, because processing queue is initially empty.
- Next 3 writes return a pending Future object, which get resolved as previous items are processed.
- First transformation is performed on the items in the order matching their
ids. - Second transformation is performed as soon as items become available. This
means that it's performed on the elements with even
ids first, because they are ready for processing earlier than the elements with oddids. - However, the ordering of the results matches the input order.
Final results look as follows:
{'id': 0, 'n': 0, 'x': 0, 'y': 0}
{'id': 1, 'n': 1, 'x': 1, 'y': 3}
{'id': 2, 'n': 0, 'x': 2, 'y': 1}
{'id': 3, 'n': 1, 'x': 3, 'y': 4}
{'id': 4, 'n': 0, 'x': 4, 'y': 2}
{'id': 5, 'n': 1, 'x': 5, 'y': 5}
The added keys indicate the order of execution of specific operations within
the IFCA transform chain. The meaning is as follows:
idis exactly the same as in input,ndenotes item parity (even items haven=0) - a visual helper to see which data points were delayed,xis the order of the execution of the first function,yis the order of the execution of the second function.
The test indicates that the chained functions are executed immediately after each other (as soon as the item is processed by one function it starts being procesed by the next function), while the read order exactly follows the write order.