In my testing this patch does look to improve the performance of copy! Nice work!
However, I was unable to find a scenerio where copy took a significant amount of time during replay.
I think we should find a case where copy takes a large amount of time during a file channel replay
before considering the change to the copy code.
However, in testing this patch, I do believe I have found the scenerio I have seen most often seen
cause long replays. In addition this is the scenerio I believe played out in
FLUME-2118. In the
thread dump attached to the ticket you see the code in FEQ.remove():
"lifecycleSupervisor-1-0" prio=10 tid=0x00007fea505f7000 nid=0x279e runnable [0x00007fe84240d000]
- locked <0x00007fe84d0007b8> (a org.apache.flume.channel.file.FlumeEventQueue)
In the attached patch, FLUME-FC-SLOW-REPLAY-1.patch which is for demonstration purposes, there is a
new file TestFileChannelReplayPerformance.java. The test in that file demonstrates the issue.
The issue is that is when there are many takes in files that don't have associated put's we search
the entire queue which is O(N) for each take in the file.
As you noted, using an fast lookup data structure would solve this. However, if it were a memory
based data structure it would also consume large amounts of memory where it did not previously.
Specifically your example of 100 million capacity would result in a 1.4GB data structure
(100 million * 16 bytes - I use 16 bytes because we have to store Long objects and assuming 64bit JVM).
I think we need an off-heap fast data structure to perform these lookups. There is a project
called MapDB (former jdbm) I have used in the past which provides such a data structure.
In the attached patch, FLUME-FC-SLOW-REPLAY-FIX-1.patch, I have used it to provide an off-heap Set
which mirrors the FEQ. Without FLUME-FC-SLOW-REPLAY-FIX-1.patch, TestFileChannelReplayPerformance
takes 50 minutes to replay while it takes only 6.5 minutes with the fix.
FlumeEventQueue.logTimings Search Count = 669000.0, Search Time = 3044957.0, Copy Count = 321014.0, Copy Time = 1103.0
TestFileChannelReplayPerformance.testReplayPerformanc Total Replay Time = 3500624
FlumeEventQueue.logTimings Search Count = 274449.0, Search Time = 1080.0, Copy Count = 274449.0, Copy Time = 1012.0
TestFileChannelReplayPerformance.testReplayPerformance Total Replay Time = 396338
NOTE: FLUME-FC-SLOW-REPLAY-1.patch and FLUME-FC-SLOW-REPLAY-FIX-1.patch are not for commit.