I have a flink python job successfully running. I'...
# troubleshooting
n
I have a flink python job successfully running. I'm not happy with the way things appear to be scaling though. I have a keyed co process function that is the bottleneck. One of my parallel handlers is seeing only 9 records per second on average. I know processing those records takes typically < 0.5 milliseconds and (rarely) at most 1-2 milliseconds. I can see that my handler is registering > 60 ms per second of "busy" time. It doesn't seem like this time is anything my application is doing. I would expect more on the order of 1-2 milliseconds busy time for this record rate. Where can I find where all this extra busy time is being consumed by? I should only have < 1000 keys at this point.
I also feel confident my task manager pods are not resource-constrained. Looking at prometheus metrics, my pods have plenty of headroom over the provided cores and CPU utilization is very low at ~100 to ~200 mcores.
d
The flink UI has built-in flamegraphs you can use to see where the time is going. The answer is usually serialization. (The rebalance you’re doing is forcing serde overhead that you could perhaps avoid.)
n
Ah. I will enable that feature and take a look. As for rebalancing, that seems to have happened automatically with how I wrote my job. I never called
.rebalance()
directly on my processed output.
d
If you are manually adjusting the parallelism on specific operators, that’s implemented as a rebalance.
n
Yup, that is what happened here. The other parts of the stream and (mostly) stateless and very fast. This co process function is a bit heavier and I wanted to bump that up to distribute the load. Then that processing output is just dumped to rabbitmq
d
That sort of tuning can be counterproductive. It’s worth experimenting to see how the tradeoffs play out for your specific use case.
You could also experiment with optimizing/changing the serializers (which can be worth up to a 10x speedup) and maybe try turning on object reuse (in combination with operator chaining), though that’s usually only a 5-15% speedup.
n
Nothing immediately obvious to my untrained eye
Is object reuse valid for pyflink jobs? Looks like the setting is supported in the python API.
k
@David Anderson @Nathanael England Same with me I have my job with Java and using Table API, By chance if you can help me here is the flame-graph
✅ 1
d
@Nathanael England Looks like flamegraphs aren't useful for inspecting pyflink jobs.
@Keyur Makwana Looks like deserialization.
n
As an update on this, I believe my bottleneck is interactions with flink-managed state. If I don't interact with state at all in my process function, my busy time drops to zero while still handling a mild number of records per second.
I first tried a no-op
process_element
method and then made it do meaningful things while not interacting with flink state. Both showed process times near zero.
However, when I do something that does require state interaction, my processing time blows back up. This is despite strongly declaring types throughout the job so that the use of slower pickle operations is avoided.
k
Ohh yes, Thanks @David Anderson I have investigated and found I was fetching Kafka property each time on the Kafka function. By optimising sink I am now getting almost 8x faster speed
🚀 1