You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pig.apache.org by "Alan Gates (JIRA)" <ji...@apache.org> on 2008/07/31 20:52:31 UTC
[jira] Created: (PIG-350) Join optimization for pipeline rework
Join optimization for pipeline rework
-------------------------------------
Key: PIG-350
URL: https://issues.apache.org/jira/browse/PIG-350
Project: Pig
Issue Type: Bug
Components: impl
Affects Versions: types_branch
Reporter: Alan Gates
Assignee: Daniel Dai
Priority: Critical
Fix For: types_branch
Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
Re: [jira] Created: (PIG-350) Join optimization for pipeline rework
Posted by Mridul Muralidharan <mr...@yahoo-inc.com>.
Hi Alan,
Please see inline.
Regards,
Mridul
Alan Gates wrote:
> In the current version, the combiner is not used with cogroup. With the
> pipeline rework going on in the types branch, the combiner will be used
> for cogroups like:
>
> C = cogroup A, B;
> D = foreach C generate project, algebraic, algebraic, ...
>
> where project is a non-UDF expression that projects fields from C and
> algebraic represents an algebraic UDF on one of the fields of C.
> Projections that are flattened will not be combined, because all the
> records are necessary to properly materialize the cross product. So
> that means the optimization proposed in pig 350 won't interact with the
> combiner.
This is great to hear, I should have followed this a bit more carefully.
Will need to consider your comment above a bit more later on, thanks !
>
> As far as cross and the combiner, we don't yet have a combiner algorithm
> for optimizing cross. This is doable but complicated. Are you
> currently using cross? We had not focussed on this as an optimization
> area because we were not aware of people who used it.
One primary usecase which comes to mind for cross is something like this :
Inspite of the obvious cost, we are having to use CROSS for applying
join constraints across 'tables' (sql like psox joins : not normal pig
table joins). So we end up with something like this currently :
entity1 = apply entity1 constraints from relevant table(s).
entity2 = apply entity2 constraints from relevant table(s).
entity3 = apply entity3 constraints from relevant table(s).
--- for inter entity constraints :
cross_res = CROSS entity1, entity2, entity3, ...;
constrained_op = FOREACH cross_res {
--- apply interentity constraints.
GENERATE valid, entity1, entity2, entity3;
};
constrained_op = FILTER constrained_op BY valid == '1'
This could be split into a series of cogroup's and filters (imo) but I
have not researched too much into that (in interest of time, nothing else).
But as should be obvious here, the cost of cross is extremely high (even
though the entity tables are constrained already - the cross can 'blow
up') ... and most (very high percentage) of the output is going to be
discarded.
Which is why, if there is any form of combiner which is applicable, or
any optimization which is possible here, it would be tremendously
benificial for us - or even any form of optimization on cross for that
matter.
>
> You mention using the combiner with filters. Were you wanting us to
> catch cases like:
>
> B = group A;
> C = filter B by $0 > 5;
> D = foreach C generate group, COUNT(A);
>
> and push both the filter and the foreach into the combiner? That is
> possible, but we have put that off in favor of instead pushing the
> filter above the group. (We don't do this filter pushing yet, but work
> is on going to develop an optimizer that will do these kinds of
> optimizations.) The only case we could think of where you wouldn't want
My current assumption was that group followed by foreach is combinable.
So my though is to use foreach also as filter - to generate a validity
flag which could be filtered later, and generate data only if this is
valid (other wise, it will be empty - thereby saving on data size).
But if both filter or both filter + foreach or combinations thereof
could be pushed as combiner, that would be absolute great.
Did not bug too much about it since we have not yet got to the stage
where these things are a concern (I am still in early prototype when I
get time).
Thanks,
Mridul
> to push the filter (and we won't) is when the filter involves a udf
> which might be very expensive to call so you want to wait until after
> the data is grouped to minimize the number of calls to the UDF.
>
> Alan.
>
> Mridul Muralidharan wrote:
>>
>> This would be absolutely great !
>> Btw, hope this continues to work fine with combiners in case of
>> COGROUP + FILTER (combiners are applicable in this case right ? or
>> only for group ?).
>>
>> Additionally, what would the impact of this be on CROSS + FILTER ? (I
>> am assuming that CROSS + FILTER is not combinable currently)
>>
>>
>> Thanks,
>> Mridul
>>
>> Alan Gates (JIRA) wrote:
>>> Join optimization for pipeline rework
>>> -------------------------------------
>>>
>>> Key: PIG-350
>>> URL: https://issues.apache.org/jira/browse/PIG-350
>>> Project: Pig
>>> Issue Type: Bug
>>> Components: impl
>>> Affects Versions: types_branch
>>> Reporter: Alan Gates
>>> Assignee: Daniel Dai
>>> Priority: Critical
>>> Fix For: types_branch
>>>
>>>
>>> Currently, joins in pig are done as groupings where each input is
>>> grouped on the join key. In the reduce phase, records from each
>>> input are collected into a bag for each key, and then a cross product
>>> done on these bags. This can be optimized by selecting one
>>> (hopefully the largest) input and streaming through it rather than
>>> placing the results in a bag. This will result in better memory
>>> usage, less spills to disk due to bag overflow, and better
>>> performance. Ideally, the system would intelligently select which
>>> input to stream, based on a histogram of value distributions for the
>>> keys. Pig does not have that kind of metadata. So for now it is
>>> best to always pick the same input (first or last) so that the user
>>> can select which input to stream.
>>>
>>> Similarly, order by in pig is done in this same way, with the
>>> grouping keys being the ordering keys, and only one input. In this
>>> case pig still currently collects all the records for a key into a
>>> bag, and then flattens the bag. This is a total waste, and in some
>>> cases causes significant performance degradation. The same
>>> optimization listed above can address this case, where the last bag
>>> (in this case the only bag) is streamed rather than collected.
>>>
>>> To do these operations, a new POJoinPackage will be needed. It will
>>> replace POPackage and the following POForEach in these types of
>>> scripts, handling pulling the records from hadoop and streaming them
>>> into the pig pipeline. A visitor will need to be added in the map
>>> reduce compilation phase that detects this case and combines the
>>> POPackage with POForeach into this new POJoinPackage.
>>>
>>
Re: [jira] Created: (PIG-350) Join optimization for pipeline rework
Posted by Alan Gates <ga...@yahoo-inc.com>.
In the current version, the combiner is not used with cogroup. With the
pipeline rework going on in the types branch, the combiner will be used
for cogroups like:
C = cogroup A, B;
D = foreach C generate project, algebraic, algebraic, ...
where project is a non-UDF expression that projects fields from C and
algebraic represents an algebraic UDF on one of the fields of C.
Projections that are flattened will not be combined, because all the
records are necessary to properly materialize the cross product. So
that means the optimization proposed in pig 350 won't interact with the
combiner.
As far as cross and the combiner, we don't yet have a combiner algorithm
for optimizing cross. This is doable but complicated. Are you
currently using cross? We had not focussed on this as an optimization
area because we were not aware of people who used it.
You mention using the combiner with filters. Were you wanting us to
catch cases like:
B = group A;
C = filter B by $0 > 5;
D = foreach C generate group, COUNT(A);
and push both the filter and the foreach into the combiner? That is
possible, but we have put that off in favor of instead pushing the
filter above the group. (We don't do this filter pushing yet, but work
is on going to develop an optimizer that will do these kinds of
optimizations.) The only case we could think of where you wouldn't want
to push the filter (and we won't) is when the filter involves a udf
which might be very expensive to call so you want to wait until after
the data is grouped to minimize the number of calls to the UDF.
Alan.
Mridul Muralidharan wrote:
>
> This would be absolutely great !
> Btw, hope this continues to work fine with combiners in case of
> COGROUP + FILTER (combiners are applicable in this case right ? or
> only for group ?).
>
> Additionally, what would the impact of this be on CROSS + FILTER ? (I
> am assuming that CROSS + FILTER is not combinable currently)
>
>
> Thanks,
> Mridul
>
> Alan Gates (JIRA) wrote:
>> Join optimization for pipeline rework
>> -------------------------------------
>>
>> Key: PIG-350
>> URL: https://issues.apache.org/jira/browse/PIG-350
>> Project: Pig
>> Issue Type: Bug
>> Components: impl
>> Affects Versions: types_branch
>> Reporter: Alan Gates
>> Assignee: Daniel Dai
>> Priority: Critical
>> Fix For: types_branch
>>
>>
>> Currently, joins in pig are done as groupings where each input is
>> grouped on the join key. In the reduce phase, records from each
>> input are collected into a bag for each key, and then a cross product
>> done on these bags. This can be optimized by selecting one
>> (hopefully the largest) input and streaming through it rather than
>> placing the results in a bag. This will result in better memory
>> usage, less spills to disk due to bag overflow, and better
>> performance. Ideally, the system would intelligently select which
>> input to stream, based on a histogram of value distributions for the
>> keys. Pig does not have that kind of metadata. So for now it is
>> best to always pick the same input (first or last) so that the user
>> can select which input to stream.
>>
>> Similarly, order by in pig is done in this same way, with the
>> grouping keys being the ordering keys, and only one input. In this
>> case pig still currently collects all the records for a key into a
>> bag, and then flattens the bag. This is a total waste, and in some
>> cases causes significant performance degradation. The same
>> optimization listed above can address this case, where the last bag
>> (in this case the only bag) is streamed rather than collected.
>>
>> To do these operations, a new POJoinPackage will be needed. It will
>> replace POPackage and the following POForEach in these types of
>> scripts, handling pulling the records from hadoop and streaming them
>> into the pig pipeline. A visitor will need to be added in the map
>> reduce compilation phase that detects this case and combines the
>> POPackage with POForeach into this new POJoinPackage.
>>
>
Re: [jira] Created: (PIG-350) Join optimization for pipeline rework
Posted by Mridul Muralidharan <mr...@yahoo-inc.com>.
This would be absolutely great !
Btw, hope this continues to work fine with combiners in case of COGROUP
+ FILTER (combiners are applicable in this case right ? or only for
group ?).
Additionally, what would the impact of this be on CROSS + FILTER ? (I am
assuming that CROSS + FILTER is not combinable currently)
Thanks,
Mridul
Alan Gates (JIRA) wrote:
> Join optimization for pipeline rework
> -------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Daniel Dai
> Priority: Critical
> Fix For: types_branch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
>
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
>
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
>
[jira] Commented: (PIG-350) PERFORMANCE: Join optimization for
pipeline rework
Posted by "Alan Gates (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12644420#action_12644420 ]
Alan Gates commented on PIG-350:
--------------------------------
In general, looks very good. One question.
In POForEach you added arrays isToBeFlattenedArray and planLeafOps, which look like copies of the lists isToBeFlattened and planLeaves respectively. In the comment on isToBeFlattenedArray you say you're doing this for performance. I think that's fine, but why do you still have the lists? Having two copies of the data seems dangerous, as you're likely to get out of sync.
> PERFORMANCE: Join optimization for pipeline rework
> --------------------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Pradeep Kamath
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch, join3.patch, join4.patch, PIG-350-2.patch, PIG-350.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (PIG-350) Join optimization for pipeline rework
Posted by "Olga Natkovich (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Olga Natkovich updated PIG-350:
-------------------------------
Status: Open (was: Patch Available)
the patch still has performance issues; can't be applied as is
> Join optimization for pipeline rework
> -------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Alan Gates
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch, join3.patch, join4.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (PIG-350) Join optimization for pipeline rework
Posted by "Alan Gates (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Alan Gates updated PIG-350:
---------------------------
Status: Patch Available (was: Open)
> Join optimization for pipeline rework
> -------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Daniel Dai
> Priority: Critical
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (PIG-350) PERFORMANCE: Join optimization for
pipeline rework
Posted by "Daniel Dai (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12642256#action_12642256 ]
Daniel Dai commented on PIG-350:
--------------------------------
Glad to see this issue is moving forward. This patch is logically good, and also include several optimization trick. Expect to see performance data. Thanks Pradeep!
> PERFORMANCE: Join optimization for pipeline rework
> --------------------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Pradeep Kamath
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch, join3.patch, join4.patch, PIG-350.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Assigned: (PIG-350) Join optimization for pipeline rework
Posted by "Olga Natkovich (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Olga Natkovich reassigned PIG-350:
----------------------------------
Assignee: Alan Gates (was: Daniel Dai)
> Join optimization for pipeline rework
> -------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Alan Gates
> Priority: Critical
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch, join3.patch, join4.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (PIG-350) PERFORMANCE: Join optimization for
pipeline rework
Posted by "Alan Gates (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Alan Gates updated PIG-350:
---------------------------
Resolution: Fixed
Status: Resolved (was: Patch Available)
PIG-350-3.patch checked in. Thanks to Pradeep and Daniel for all your work on this.
> PERFORMANCE: Join optimization for pipeline rework
> --------------------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Pradeep Kamath
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch, join3.patch, join4.patch, PIG-350-2.patch, PIG-350-3.patch, PIG-350.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (PIG-350) Join optimization for pipeline rework
Posted by "Daniel Dai (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Daniel Dai updated PIG-350:
---------------------------
Attachment: join4.patch
Make several changes for performance optimization.
> Join optimization for pipeline rework
> -------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Daniel Dai
> Priority: Critical
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch, join3.patch, join4.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (PIG-350) PERFORMANCE: Join optimization for
pipeline rework
Posted by "Olga Natkovich (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Olga Natkovich updated PIG-350:
-------------------------------
Summary: PERFORMANCE: Join optimization for pipeline rework (was: Join optimization for pipeline rework)
> PERFORMANCE: Join optimization for pipeline rework
> --------------------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Alan Gates
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch, join3.patch, join4.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (PIG-350) PERFORMANCE: Join optimization for
pipeline rework
Posted by "Pradeep Kamath (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Pradeep Kamath updated PIG-350:
-------------------------------
Attachment: PIG-350-3.patch
New version with above review comment incorporated - now we only have array and no arraylist for the data structures mentioned in the comment.
> PERFORMANCE: Join optimization for pipeline rework
> --------------------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Pradeep Kamath
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch, join3.patch, join4.patch, PIG-350-2.patch, PIG-350-3.patch, PIG-350.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (PIG-350) Join optimization for pipeline rework
Posted by "Alan Gates (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12620469#action_12620469 ]
Alan Gates commented on PIG-350:
--------------------------------
Comments:
1. In PigTupleReverseOrderWritableComarator and PigTupleReverseOrderWritableGroupComarator it looks to me like you're assuming that tuples from a cogroup only have one field from each. But that may not be the case if there are multiple columns in the cogroup statement, such as:
C = cogroup A by ($0, $1), B by ($1, $2)
2. In JoinOptimizationVisitor where you remove the POPackage and POForeach and replace it with POJoinPackage, you should use OperatorPlan.replace to remove the POForeach and add the POJoinPackage. This will preserve any ordering in the graph that might be lost otherwise.
> Join optimization for pipeline rework
> -------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Daniel Dai
> Priority: Critical
> Fix For: types_branch
>
> Attachments: join.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (PIG-350) Join optimization for pipeline rework
Posted by "Olga Natkovich (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12620670#action_12620670 ]
Olga Natkovich commented on PIG-350:
------------------------------------
the patch looks good to me
> Join optimization for pipeline rework
> -------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Daniel Dai
> Priority: Critical
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (PIG-350) PERFORMANCE: Join optimization for
pipeline rework
Posted by "Pradeep Kamath (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Pradeep Kamath updated PIG-350:
-------------------------------
Attachment: PIG-350.patch
> PERFORMANCE: Join optimization for pipeline rework
> --------------------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Pradeep Kamath
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch, join3.patch, join4.patch, PIG-350.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (PIG-350) PERFORMANCE: Join optimization for
pipeline rework
Posted by "Pradeep Kamath (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Pradeep Kamath updated PIG-350:
-------------------------------
Assignee: Pradeep Kamath (was: Alan Gates)
Status: Patch Available (was: Open)
> PERFORMANCE: Join optimization for pipeline rework
> --------------------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Pradeep Kamath
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch, join3.patch, join4.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (PIG-350) PERFORMANCE: Join optimization for
pipeline rework
Posted by "Pradeep Kamath (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Pradeep Kamath updated PIG-350:
-------------------------------
Attachment: PIG-350-2.patch
Attached new version of the patch with following changes:
- Added optimizations in POForeach to store isToBeFlattened arraylist of Booleans to a static array of booleans - this saves on get() calls and on conversions from Boolean to boolean in all the checks for flatten for an input
- POJoinPackage now sends the last inputs in chunk sizes (default of 1000) which can be changed by the system property "join.biggest.input.chunksize"
- Rolled back changes in previous patch to reuse data structures (arrays) in POForeach - runs with big data showed that this caused GC overhead issues - the possible explanation for this is that these arrays on reuse go into the old generation of the heap causing the GC more problems to reclaim space
- tightened the code a little more in POJoinPackage
> PERFORMANCE: Join optimization for pipeline rework
> --------------------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Pradeep Kamath
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch, join3.patch, join4.patch, PIG-350-2.patch, PIG-350.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (PIG-350) Join optimization for pipeline rework
Posted by "Olga Natkovich (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12623490#action_12623490 ]
Olga Natkovich commented on PIG-350:
------------------------------------
Daniel run a large test but the optimized code is still significantly slower. The spill time was about 5 minutes on the old code. He did not measure the read/parse time.
Without patch: 6:36:0
With patch: 6:55:25
> Join optimization for pipeline rework
> -------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Alan Gates
> Priority: Critical
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch, join3.patch, join4.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (PIG-350) Join optimization for pipeline rework
Posted by "Daniel Dai (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Daniel Dai updated PIG-350:
---------------------------
Attachment: join.patch
Here are some notes for this patch:
# The criteria for join optimization
a. POPackage->POForEach is the root of reduce plan
b. POUnion is the leaf of map plan (so that we exclude distinct, sort...)
c. No combiner plan
d. POForEach nested plan only contains POProject in any depth
# If the MR plan is not eligible for optimization, everything stay the same
# The first alias in cogroup statement is the one we are going to stream.
# In optimization case, we will change the output key format for map-reduce, originally it is (key, IndexedTuple), now it is ((old_key, index), IndexedTuple)
# Here is the layout for patitioner, comparator for new key
#* Partition key: (old_key, index)
#* OutputKeyComparator: by old_key + reverse index
#* OutputValueGroupingComparator: by old_key
With this layout, we get
## If two inputs share the same old_key, they go to the same reducer
## For every old_key, reduce function is called once
## Values iterator are sorted on reverse index order, so that we can materialize n-1 inputs, then stream the first input
# Implementation detail for POJoinPackage:
a. For every tuple in the first input, combine it with materialized n-1 inputs, feed to delegated ForEach operator
b. Call getNext on ForEach until nothing available, then feed the next tuple
c. Maintain internal status, since we feed POJoinPackage once, and then call getNext multiple times
# For performance reason, I use a byte level comparator for OutputKeyComparator, there is no byte level comparator for partitioner and OutputValueGroupingComparator in hadoop probably because OutputKeyComparator is more critical than others. While OutputValueGroupingComparator and partitioner is called one tuple a time, OutputKeyComparator is called more frequently
Possible improvement:
# User is able to give a hint for which alias to use for stream, we can change OutputKeyComparator to implement it easily
> Join optimization for pipeline rework
> -------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Daniel Dai
> Priority: Critical
> Fix For: types_branch
>
> Attachments: join.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (PIG-350) PERFORMANCE: Join optimization for
pipeline rework
Posted by "Pradeep Kamath (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12641460#action_12641460 ]
Pradeep Kamath commented on PIG-350:
------------------------------------
Submitted patch with modification to Join4.patch
- The last input is now streamed instead of the first input. This is because we now have tuples arriving in package in the order of the index starting from input 0 upto input n. All tuples for a given index (input) arrive before any tuple for the next index.
- The last input is now sent as a tuple at a time to foreach rather than as a bag containing one tuple at a time
- A new optimized foreach has been introduced which assumes its input has already been "attached" (which will be the case in the join optimization)
- In POForeach all data structures (arrays) are now created statically and reused in each getNext() call rather than being re-created on each getNext() call. Likewise the datastructures in POJoinPackage are also created once up front and reused.
> PERFORMANCE: Join optimization for pipeline rework
> --------------------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Pradeep Kamath
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch, join3.patch, join4.patch, PIG-350.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (PIG-350) Join optimization for pipeline rework
Posted by "Daniel Dai (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Daniel Dai updated PIG-350:
---------------------------
Attachment: join3.patch
Try join3.patch
> Join optimization for pipeline rework
> -------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Daniel Dai
> Priority: Critical
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch, join3.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (PIG-350) Join optimization for pipeline rework
Posted by "Alan Gates (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12620728#action_12620728 ]
Alan Gates commented on PIG-350:
--------------------------------
Cogroups that use inner return wrong results. Scripts like:
{code}
e = cogroup c by $0, d by $0;
f = foreach e generate flatten (c), flatten(d);
{code}
do fine but scripts like:
{code}
c = filter a by age < 20;
e = cogroup c by (name, age), b by (name, age) inner;
{code}
return wrong results.
> Join optimization for pipeline rework
> -------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Daniel Dai
> Priority: Critical
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (PIG-350) Join optimization for pipeline rework
Posted by "Olga Natkovich (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Olga Natkovich updated PIG-350:
-------------------------------
Priority: Major (was: Critical)
reducing priority since so far we have not been able to figure a way to make this code run efficiently. will revisit later
> Join optimization for pipeline rework
> -------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Alan Gates
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch, join3.patch, join4.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Issue Comment Edited: (PIG-350) Join optimization for
pipeline rework
Posted by "Daniel Dai (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12620448#action_12620448 ]
daijy edited comment on PIG-350 at 8/6/08 3:30 PM:
--------------------------------------------------------
Here are some notes for this patch:
# The criteria for join optimization
a. POPackage->POForEach is the root of reduce plan
b. POUnion is the leaf of map plan (so that we exclude distinct, sort...)
c. No combiner plan
d. POForEach nested plan only contains POProject in any depth
e. Inside POForEach, all occurrences of the first input are flattened
# If the MR plan is not eligible for optimization, everything stay the same
# The first alias in cogroup statement is the one we are going to stream.
# In optimization case, we will change the output key format for map-reduce, originally it is (key, IndexedTuple), now it is ((old_key, index), IndexedTuple)
# Here is the layout for patitioner, comparator for new key
#* Partition key: (old_key, index)
#* OutputKeyComparator: by old_key + reverse index
#* OutputValueGroupingComparator: by old_key
With this layout, we get
## If two inputs share the same old_key, they go to the same reducer
## For every old_key, reduce function is called once
## Values iterator are sorted on reverse index order, so that we can materialize n-1 inputs, then stream the first input
# Implementation detail for POJoinPackage:
a. For every tuple in the first input, combine it with materialized n-1 inputs, feed to delegated ForEach operator
b. Call getNext on ForEach until nothing available, then feed the next tuple
c. Maintain internal status, since we feed POJoinPackage once, and then call getNext multiple times
# For performance reason, I use a byte level comparator for OutputKeyComparator, there is no byte level comparator for partitioner and OutputValueGroupingComparator in hadoop probably because OutputKeyComparator is more critical than others. While OutputValueGroupingComparator and partitioner is called one tuple a time, OutputKeyComparator is called more frequently
Possible improvement:
# User is able to give a hint for which alias to use for stream, we can change OutputKeyComparator to implement it easily
was (Author: daijy):
Here are some notes for this patch:
# The criteria for join optimization
a. POPackage->POForEach is the root of reduce plan
b. POUnion is the leaf of map plan (so that we exclude distinct, sort...)
c. No combiner plan
d. POForEach nested plan only contains POProject in any depth
# If the MR plan is not eligible for optimization, everything stay the same
# The first alias in cogroup statement is the one we are going to stream.
# In optimization case, we will change the output key format for map-reduce, originally it is (key, IndexedTuple), now it is ((old_key, index), IndexedTuple)
# Here is the layout for patitioner, comparator for new key
#* Partition key: (old_key, index)
#* OutputKeyComparator: by old_key + reverse index
#* OutputValueGroupingComparator: by old_key
With this layout, we get
## If two inputs share the same old_key, they go to the same reducer
## For every old_key, reduce function is called once
## Values iterator are sorted on reverse index order, so that we can materialize n-1 inputs, then stream the first input
# Implementation detail for POJoinPackage:
a. For every tuple in the first input, combine it with materialized n-1 inputs, feed to delegated ForEach operator
b. Call getNext on ForEach until nothing available, then feed the next tuple
c. Maintain internal status, since we feed POJoinPackage once, and then call getNext multiple times
# For performance reason, I use a byte level comparator for OutputKeyComparator, there is no byte level comparator for partitioner and OutputValueGroupingComparator in hadoop probably because OutputKeyComparator is more critical than others. While OutputValueGroupingComparator and partitioner is called one tuple a time, OutputKeyComparator is called more frequently
Possible improvement:
# User is able to give a hint for which alias to use for stream, we can change OutputKeyComparator to implement it easily
> Join optimization for pipeline rework
> -------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Daniel Dai
> Priority: Critical
> Fix For: types_branch
>
> Attachments: join.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (PIG-350) Join optimization for pipeline rework
Posted by "Daniel Dai (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PIG-350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Daniel Dai updated PIG-350:
---------------------------
Attachment: join2.patch
In response to Alan's comments:
1. Tested with multiple key cases, works fine
2. Changed the patch to use OperatorPlan.replace instead of remove and then add
> Join optimization for pipeline rework
> -------------------------------------
>
> Key: PIG-350
> URL: https://issues.apache.org/jira/browse/PIG-350
> Project: Pig
> Issue Type: Bug
> Components: impl
> Affects Versions: types_branch
> Reporter: Alan Gates
> Assignee: Daniel Dai
> Priority: Critical
> Fix For: types_branch
>
> Attachments: join.patch, join2.patch
>
>
> Currently, joins in pig are done as groupings where each input is grouped on the join key. In the reduce phase, records from each input are collected into a bag for each key, and then a cross product done on these bags. This can be optimized by selecting one (hopefully the largest) input and streaming through it rather than placing the results in a bag. This will result in better memory usage, less spills to disk due to bag overflow, and better performance. Ideally, the system would intelligently select which input to stream, based on a histogram of value distributions for the keys. Pig does not have that kind of metadata. So for now it is best to always pick the same input (first or last) so that the user can select which input to stream.
> Similarly, order by in pig is done in this same way, with the grouping keys being the ordering keys, and only one input. In this case pig still currently collects all the records for a key into a bag, and then flattens the bag. This is a total waste, and in some cases causes significant performance degradation. The same optimization listed above can address this case, where the last bag (in this case the only bag) is streamed rather than collected.
> To do these operations, a new POJoinPackage will be needed. It will replace POPackage and the following POForEach in these types of scripts, handling pulling the records from hadoop and streaming them into the pig pipeline. A visitor will need to be added in the map reduce compilation phase that detects this case and combines the POPackage with POForeach into this new POJoinPackage.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.