SlideShare a Scribd company logo
1 of 32
Big DATA SKEW
Ayan Ray
Big Data Analytics Engineer
© 2016 RS Software (India) Ltd. 2
Index
• Definition
• Types
• Problem in Hadoop
• Problem Solving Approaches
• Mapreduce
• Hive
• Pig
© 2016 RS Software (India) Ltd. 3
Definition
Skewness is the measure of asymmetry of the
probability distribution of a real-valued random variable
about its mean.
© 2016 RS Software (India) Ltd. 4
Types
Negative/Left
• The left tail is longer; the mass of the distribution is
concentrated on the right.
• Mean is at left of the peak i.e Mean of the data is less
than median.
© 2016 RS Software (India) Ltd. 5
Types
Positive/Right
• The right tail is longer; the mass of the distribution is
concentrated on the left.
• Mean is at right of the peak i.e Mean of the data
values is larger than the median.
© 2016 RS Software (India) Ltd. 6
Types
No Skew/ Normal Distribution
A normal distribution is not skewed.
It is perfectly symmetrical.
Mean is exactly at the peak. Mean=median
© 2016 RS Software (India) Ltd. 7
Problem in Hadoop
• Say, we have to process some twitter feed
corresponding to a user, each of which is in the
format <twitter_id, twitter_post>
• Now, say some of the users are very active on twitter
and some seldom uses it.
• The heavy user will have a very large number of <id,
post> data.
• When, we will try to process the data through a
Mapreduce job, the reducer assigned with heavy user
will take long time to complete.
• This will result in high over all time and low resource
utilization.
© 2016 RS Software (India) Ltd. 8
Solution in Mapreduce
Combiner
• Implement a combiner to reduce the amount of data
going into the reduce-phase. This will significantly
reduce the effects of any type of reduce-side skew.
• Combiners are effective at handling Partitioning
Skew and Expensive Input at the reduce side when
the skew observed during reduce phase is mainly due
to the volume of data transferred during the shuffle
phase.
• But we can’t run combiner in all cases especially
when reducer calculation is associative /commutative
(say average)
© 2016 RS Software (India) Ltd. 9
Solution in Mapreduce
Partitioner
• This phase exist between map and reduce phase.
• Number of reducers is equal to number of
Partitioner.
• Partitioner has an inherent method as follows:
int getPartition(K key, V value, int numReduceTasks)
• Based on the integer value returned from the above
function, Hadoop selects node where the reduce task
for a particular key should run.
• We can manipulate the above method, to write our
own custom Partitioner.
© 2016 RS Software (India) Ltd. 10
Solution in Mapreduce
Partitioner-Continued
• By default, all values for a particular key goes to same
reducer.
• Say, if we know that there is possibility that values
for a particular key will be overcrowded then we can
write our custom partitioner to divide it further to
different reducers.
Let us take an example,
• We are trying to find out highest salaried employee
by gender in different age groups (e.g below 20,
between 20 and 40 and above 40)
© 2016 RS Software (India) Ltd. 11
Solution in Mapreduce
Partitioner-Continued
Input Data:
Id Name Age Gender Salary
1201 gopal 45 Male 50,000
1202 manisha 40 Female 50,000
1203 khalil 34 Male 30,000
1204 prasanth 30 Male 30,000
1205 kiran 20 Male 40,000
1206 laxmi 25 Female 35,000
1207 bhavya 20 Female 15,000
1208 reshma 19 Female 15,000
1209 kranthi 22 Male 22,000
© 2016 RS Software (India) Ltd. 12
Solution in Mapreduce
Partitioner-Continued
© 2016 RS Software (India) Ltd. 13
Solution in Mapreduce
Partitioner-Continued
If we analyse the data, we will find that we have
following number of records for each category
We can observe that the age range 20<=x<=40 is
overcrowded.
Range Count
<20=1 1
20<=x<=40 6
>40 1
© 2016 RS Software (India) Ltd. 14
Solution in Mapreduce
Partitioner-Continued
• Hence, the reducer 1 will take much longer time as
compared to other 2 reducers.
• So, the other 2 reducers will have to wait as reducer 1
will carry on its processing.
• We can split them into different reducers.
© 2016 RS Software (India) Ltd. 15
Solution in Mapreduce
Partitioner-Continued
© 2016 RS Software (India) Ltd. 16
Solution in Mapreduce
Partitioner-Continued
Now, the load will be more uniformly distributed and the
skew effect will be dampened.
Range Count
<20=1 1
20<=x<=40 && salary <35000=3 3
20<=x<=40 && salary >=35000=3 3
>40 1
© 2016 RS Software (India) Ltd. 17
Solution in Mapreduce
Combiner and Partitioner
Both combiner and partitioner can be combined and
used in the same job where possible.
© 2016 RS Software (India) Ltd. 18
Solution in Hive
Skewed table
• A skewed table is a special type of table where the
values that appear very often (heavy skew) are split
out into separate files and rest of the values go to
some other file.
• Syntax:
create table <T> (schema) skewed by (keys) on ('c1', 'c2')
[STORED as DIRECTORIES];
• Example:
create table T (c1 string, c2 string) skewed by (c1) on
('x1');
© 2016 RS Software (India) Ltd. 19
Solution in Hive
How does it solve Data skew?
• By specifying the skewed values Hive will split those
out into separate files automatically.
• It takes this fact into account during queries so that it
can skip (or include) whole files if possible thus
enhancing the performance.
© 2016 RS Software (India) Ltd. 20
Solution in Hive
List Bucketing
• List bucketing is a special type of Skewed table where
we identify the keys which are highly skewed and
maintain one directory per skewed key. The data
corresponding to remaining (non-skewed) keys go
into separate directory.
© 2016 RS Software (India) Ltd. 21
Solution in Hive
Single key
Create table list_bucketed_table (c1 int, c2 int, c3 int)
skewed by (c1) on (10,20,30) stored as directories;
• This will create separate directories for c1 values of
10, 20 and 30 and another one directory for all other
values.
Select c1, c2, c3 from list_bucketed_table where c1=10;
• The Hive compiler will only use the directory
corresponding to x=30 for the map-reduce job.
Select c1, c2, c3 from list_bucketed_table where c1=10;
• The Hive compiler will only use the directory
corresponding to x=others for the map-reduce job.
© 2016 RS Software (India) Ltd. 22
Solution in Hive
Multiple key
Create table list_bucketed_table (c1 string, c2 int, c3 int)
skewed by (c1, c2) on ((‘a’, 10), (‘b’, 20)) stored as
directories;
The metastore will have mapping like (‘a’, 10)->1 , (‘b’,20)
->2 , others -> 3.
Select c1, c2, c3 from list_bucketed_table where c1=’a’ and
c2=10;
The Hive query will use the file from directory (‘a’,10) -> 1
© 2016 RS Software (India) Ltd. 23
Solution in Hive
Multiple key
Create table list_bucketed_table (c1 string, c2 int, c3 int)
skewed by (c1, c2) on ((‘a’, 10), (‘b’, 20)) stored as
directories;
The metastore will have mapping like (‘a’, 10)->1 , (‘b’,20)
->2 , others -> 3.
Select c1, c2, c3 from list_bucketed_table where c1=’a’ and
c2=10;
The Hive query will use the file from directory (‘a’,10) -> 1
© 2016 RS Software (India) Ltd. 24
Solution in Hive
Advantages:
• Each partition’s skewed keys accounts for a
significant percentage of the total data. In the above
scenario if skewed keys 10,20 and 30 occupy
significant portion of the data then queries of the
form x=40 will need not require to scan the
remaining portion of the data.
• The number of skewed keys per partition is small.
Since this list is stored in metastore, so it does not
make sense to store very large number of keys per
partition in the metastore.
© 2016 RS Software (India) Ltd. 25
Solution in Hive
Disadvantages:
• The approach is not scalable when the number of
skewed keys is very large. This creates a problem for
metastore capability.
• It is also not scalable suited when number of skewed
keys is more than 1 but in the query all the keys are
not specified.
• It will not give desired result when skewed keys
occupy very less percentage of the total data.
© 2016 RS Software (India) Ltd. 26
Solution in Hive
Disadvantages:
• The approach is not scalable when the number of
skewed keys is very large. This creates a problem for
metastore capability.
• It is also not scalable suited when number of skewed
keys is more than 1 but in the query all the keys are
not specified.
• It will not give desired result when skewed keys
occupy very less percentage of the total data.
© 2016 RS Software (India) Ltd. 27
Solution in Pig
Skewed Join
• Skew join works by first sampling one input for the
join.
• Skew join is capable of identifying that it will not be
able to fit the entire input into memory hence, splits
them into two reducers.
• For all records except those identified in the sample,
it does a standard join, collecting records with the
same key onto the same reducer.
• The second input is the one that is sampled and have
its keys with large number of values split across
reducers. The first input will have those values
replicated across reducers.
© 2016 RS Software (India) Ltd. 28
Solution in Pig
For example,
Employee= load ‘employee’ as (name:chararray,
city:chararray);
Citydetails= load ‘employee’ as (city: chararray,
population: int);
Joinop= join Citydetails by city, users by city using
‘skewed’;
Suppose the distribution is as follows:
20 users live in Bangalore
10000 users live in Kolkata,
300 users live in Chennai.
© 2016 RS Software (India) Ltd. 29
Solution in Pig
• Let us assume that Pig determined that 7500 records
could be fitted into memory.
• If we don’t use skew Pig will throw OutOfMemory
exception
• But with the use of skew it will separate users with
Kolkata as key into two reducers.
© 2016 RS Software (India) Ltd. 30
Solution in Pig
Memory Usage
• Pig looks at the record sizes in the sample and
assumes it can use 30%(default) of the JVM’s heap to
materialize records that will be joined.
• Memory should be decreased if the join is still failing
due to out-of-memory errors even using skew join.
• So you should tell it to use less.
© 2016 RS Software (India) Ltd. 31
Solution in Pig
Memory Usage
Memory allocation can be configured manually using the
following configuration
pig.skewedjoin.reduce.memusage=0.25
It can be passed from command line also
-D pig.skewedjoin.reduce.memusage=0.25
This will use 25% instead of 30%.
© 2016 RS Software (India) Ltd. 32
Thanking You!
For further assistance and explanation in anything
related to Big Data feel free to mail me at
ayanray089@gmail.com

More Related Content

Similar to Big data skew

Production model lifecycle management 2016 09
Production model lifecycle management 2016 09Production model lifecycle management 2016 09
Production model lifecycle management 2016 09Greg Makowski
 
Stratosphere with big_data_analytics
Stratosphere with big_data_analyticsStratosphere with big_data_analytics
Stratosphere with big_data_analyticsAvinash Pandu
 
Hadoop training-in-hyderabad
Hadoop training-in-hyderabadHadoop training-in-hyderabad
Hadoop training-in-hyderabadsreehari orienit
 
Shuffle sort 101
Shuffle sort 101Shuffle sort 101
Shuffle sort 101Jeff Bean
 
Design patterns in MapReduce
Design patterns in MapReduceDesign patterns in MapReduce
Design patterns in MapReduceAkhilesh Joshi
 
MapReduce
MapReduceMapReduce
MapReduceKavyaGo
 
Hadoop and HBase experiences in perf log project
Hadoop and HBase experiences in perf log projectHadoop and HBase experiences in perf log project
Hadoop and HBase experiences in perf log projectMao Geng
 
Interactive SQL POC on Hadoop (Hive, Presto and Hive-on-Tez)
Interactive SQL POC on Hadoop (Hive, Presto and Hive-on-Tez)Interactive SQL POC on Hadoop (Hive, Presto and Hive-on-Tez)
Interactive SQL POC on Hadoop (Hive, Presto and Hive-on-Tez)Sudhir Mallem
 
Seminar Presentation Hadoop
Seminar Presentation HadoopSeminar Presentation Hadoop
Seminar Presentation HadoopVarun Narang
 
Mapreduce script
Mapreduce scriptMapreduce script
Mapreduce scriptHaripritha
 
[Cassandra summit Tokyo, 2015] Cassandra 2015 最新情報 by ジョナサン・エリス(Jonathan Ellis)
[Cassandra summit Tokyo, 2015] Cassandra 2015 最新情報 by ジョナサン・エリス(Jonathan Ellis)[Cassandra summit Tokyo, 2015] Cassandra 2015 最新情報 by ジョナサン・エリス(Jonathan Ellis)
[Cassandra summit Tokyo, 2015] Cassandra 2015 最新情報 by ジョナサン・エリス(Jonathan Ellis)datastaxjp
 
module3part-1-bigdata-230301002404-3db4f2a4 (1).pdf
module3part-1-bigdata-230301002404-3db4f2a4 (1).pdfmodule3part-1-bigdata-230301002404-3db4f2a4 (1).pdf
module3part-1-bigdata-230301002404-3db4f2a4 (1).pdfTSANKARARAO
 
AWS Summit 2013 | Auckland - Big Data Analytics
AWS Summit 2013 | Auckland - Big Data AnalyticsAWS Summit 2013 | Auckland - Big Data Analytics
AWS Summit 2013 | Auckland - Big Data AnalyticsAmazon Web Services
 
HBaseCon2017 Improving HBase availability in a multi tenant environment
HBaseCon2017 Improving HBase availability in a multi tenant environmentHBaseCon2017 Improving HBase availability in a multi tenant environment
HBaseCon2017 Improving HBase availability in a multi tenant environmentHBaseCon
 

Similar to Big data skew (20)

Hadoop Interview Questions and Answers
Hadoop Interview Questions and AnswersHadoop Interview Questions and Answers
Hadoop Interview Questions and Answers
 
2 mapreduce-model-principles
2 mapreduce-model-principles2 mapreduce-model-principles
2 mapreduce-model-principles
 
Hadoop
HadoopHadoop
Hadoop
 
Production model lifecycle management 2016 09
Production model lifecycle management 2016 09Production model lifecycle management 2016 09
Production model lifecycle management 2016 09
 
Stratosphere with big_data_analytics
Stratosphere with big_data_analyticsStratosphere with big_data_analytics
Stratosphere with big_data_analytics
 
Hadoop training-in-hyderabad
Hadoop training-in-hyderabadHadoop training-in-hyderabad
Hadoop training-in-hyderabad
 
Shuffle sort 101
Shuffle sort 101Shuffle sort 101
Shuffle sort 101
 
Design patterns in MapReduce
Design patterns in MapReduceDesign patterns in MapReduce
Design patterns in MapReduce
 
MapReduce
MapReduceMapReduce
MapReduce
 
Hadoop and HBase experiences in perf log project
Hadoop and HBase experiences in perf log projectHadoop and HBase experiences in perf log project
Hadoop and HBase experiences in perf log project
 
Interactive SQL POC on Hadoop (Hive, Presto and Hive-on-Tez)
Interactive SQL POC on Hadoop (Hive, Presto and Hive-on-Tez)Interactive SQL POC on Hadoop (Hive, Presto and Hive-on-Tez)
Interactive SQL POC on Hadoop (Hive, Presto and Hive-on-Tez)
 
Big data analytics using R
Big data analytics using RBig data analytics using R
Big data analytics using R
 
Seminar Presentation Hadoop
Seminar Presentation HadoopSeminar Presentation Hadoop
Seminar Presentation Hadoop
 
Mapreduce script
Mapreduce scriptMapreduce script
Mapreduce script
 
[Cassandra summit Tokyo, 2015] Cassandra 2015 最新情報 by ジョナサン・エリス(Jonathan Ellis)
[Cassandra summit Tokyo, 2015] Cassandra 2015 最新情報 by ジョナサン・エリス(Jonathan Ellis)[Cassandra summit Tokyo, 2015] Cassandra 2015 最新情報 by ジョナサン・エリス(Jonathan Ellis)
[Cassandra summit Tokyo, 2015] Cassandra 2015 最新情報 by ジョナサン・エリス(Jonathan Ellis)
 
Map reduce prashant
Map reduce prashantMap reduce prashant
Map reduce prashant
 
module3part-1-bigdata-230301002404-3db4f2a4 (1).pdf
module3part-1-bigdata-230301002404-3db4f2a4 (1).pdfmodule3part-1-bigdata-230301002404-3db4f2a4 (1).pdf
module3part-1-bigdata-230301002404-3db4f2a4 (1).pdf
 
Big Data.pptx
Big Data.pptxBig Data.pptx
Big Data.pptx
 
AWS Summit 2013 | Auckland - Big Data Analytics
AWS Summit 2013 | Auckland - Big Data AnalyticsAWS Summit 2013 | Auckland - Big Data Analytics
AWS Summit 2013 | Auckland - Big Data Analytics
 
HBaseCon2017 Improving HBase availability in a multi tenant environment
HBaseCon2017 Improving HBase availability in a multi tenant environmentHBaseCon2017 Improving HBase availability in a multi tenant environment
HBaseCon2017 Improving HBase availability in a multi tenant environment
 

Recently uploaded

Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Delhi Call girls
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Valters Lauzums
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% SecurePooja Nehwal
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...amitlee9823
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...shivangimorya083
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxolyaivanovalion
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Researchmichael115558
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxJohnnyPlasten
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusTimothy Spann
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023ymrp368
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Delhi Call girls
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFxolyaivanovalion
 

Recently uploaded (20)

Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptx
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 

Big data skew

  • 1. Big DATA SKEW Ayan Ray Big Data Analytics Engineer
  • 2. © 2016 RS Software (India) Ltd. 2 Index • Definition • Types • Problem in Hadoop • Problem Solving Approaches • Mapreduce • Hive • Pig
  • 3. © 2016 RS Software (India) Ltd. 3 Definition Skewness is the measure of asymmetry of the probability distribution of a real-valued random variable about its mean.
  • 4. © 2016 RS Software (India) Ltd. 4 Types Negative/Left • The left tail is longer; the mass of the distribution is concentrated on the right. • Mean is at left of the peak i.e Mean of the data is less than median.
  • 5. © 2016 RS Software (India) Ltd. 5 Types Positive/Right • The right tail is longer; the mass of the distribution is concentrated on the left. • Mean is at right of the peak i.e Mean of the data values is larger than the median.
  • 6. © 2016 RS Software (India) Ltd. 6 Types No Skew/ Normal Distribution A normal distribution is not skewed. It is perfectly symmetrical. Mean is exactly at the peak. Mean=median
  • 7. © 2016 RS Software (India) Ltd. 7 Problem in Hadoop • Say, we have to process some twitter feed corresponding to a user, each of which is in the format <twitter_id, twitter_post> • Now, say some of the users are very active on twitter and some seldom uses it. • The heavy user will have a very large number of <id, post> data. • When, we will try to process the data through a Mapreduce job, the reducer assigned with heavy user will take long time to complete. • This will result in high over all time and low resource utilization.
  • 8. © 2016 RS Software (India) Ltd. 8 Solution in Mapreduce Combiner • Implement a combiner to reduce the amount of data going into the reduce-phase. This will significantly reduce the effects of any type of reduce-side skew. • Combiners are effective at handling Partitioning Skew and Expensive Input at the reduce side when the skew observed during reduce phase is mainly due to the volume of data transferred during the shuffle phase. • But we can’t run combiner in all cases especially when reducer calculation is associative /commutative (say average)
  • 9. © 2016 RS Software (India) Ltd. 9 Solution in Mapreduce Partitioner • This phase exist between map and reduce phase. • Number of reducers is equal to number of Partitioner. • Partitioner has an inherent method as follows: int getPartition(K key, V value, int numReduceTasks) • Based on the integer value returned from the above function, Hadoop selects node where the reduce task for a particular key should run. • We can manipulate the above method, to write our own custom Partitioner.
  • 10. © 2016 RS Software (India) Ltd. 10 Solution in Mapreduce Partitioner-Continued • By default, all values for a particular key goes to same reducer. • Say, if we know that there is possibility that values for a particular key will be overcrowded then we can write our custom partitioner to divide it further to different reducers. Let us take an example, • We are trying to find out highest salaried employee by gender in different age groups (e.g below 20, between 20 and 40 and above 40)
  • 11. © 2016 RS Software (India) Ltd. 11 Solution in Mapreduce Partitioner-Continued Input Data: Id Name Age Gender Salary 1201 gopal 45 Male 50,000 1202 manisha 40 Female 50,000 1203 khalil 34 Male 30,000 1204 prasanth 30 Male 30,000 1205 kiran 20 Male 40,000 1206 laxmi 25 Female 35,000 1207 bhavya 20 Female 15,000 1208 reshma 19 Female 15,000 1209 kranthi 22 Male 22,000
  • 12. © 2016 RS Software (India) Ltd. 12 Solution in Mapreduce Partitioner-Continued
  • 13. © 2016 RS Software (India) Ltd. 13 Solution in Mapreduce Partitioner-Continued If we analyse the data, we will find that we have following number of records for each category We can observe that the age range 20<=x<=40 is overcrowded. Range Count <20=1 1 20<=x<=40 6 >40 1
  • 14. © 2016 RS Software (India) Ltd. 14 Solution in Mapreduce Partitioner-Continued • Hence, the reducer 1 will take much longer time as compared to other 2 reducers. • So, the other 2 reducers will have to wait as reducer 1 will carry on its processing. • We can split them into different reducers.
  • 15. © 2016 RS Software (India) Ltd. 15 Solution in Mapreduce Partitioner-Continued
  • 16. © 2016 RS Software (India) Ltd. 16 Solution in Mapreduce Partitioner-Continued Now, the load will be more uniformly distributed and the skew effect will be dampened. Range Count <20=1 1 20<=x<=40 && salary <35000=3 3 20<=x<=40 && salary >=35000=3 3 >40 1
  • 17. © 2016 RS Software (India) Ltd. 17 Solution in Mapreduce Combiner and Partitioner Both combiner and partitioner can be combined and used in the same job where possible.
  • 18. © 2016 RS Software (India) Ltd. 18 Solution in Hive Skewed table • A skewed table is a special type of table where the values that appear very often (heavy skew) are split out into separate files and rest of the values go to some other file. • Syntax: create table <T> (schema) skewed by (keys) on ('c1', 'c2') [STORED as DIRECTORIES]; • Example: create table T (c1 string, c2 string) skewed by (c1) on ('x1');
  • 19. © 2016 RS Software (India) Ltd. 19 Solution in Hive How does it solve Data skew? • By specifying the skewed values Hive will split those out into separate files automatically. • It takes this fact into account during queries so that it can skip (or include) whole files if possible thus enhancing the performance.
  • 20. © 2016 RS Software (India) Ltd. 20 Solution in Hive List Bucketing • List bucketing is a special type of Skewed table where we identify the keys which are highly skewed and maintain one directory per skewed key. The data corresponding to remaining (non-skewed) keys go into separate directory.
  • 21. © 2016 RS Software (India) Ltd. 21 Solution in Hive Single key Create table list_bucketed_table (c1 int, c2 int, c3 int) skewed by (c1) on (10,20,30) stored as directories; • This will create separate directories for c1 values of 10, 20 and 30 and another one directory for all other values. Select c1, c2, c3 from list_bucketed_table where c1=10; • The Hive compiler will only use the directory corresponding to x=30 for the map-reduce job. Select c1, c2, c3 from list_bucketed_table where c1=10; • The Hive compiler will only use the directory corresponding to x=others for the map-reduce job.
  • 22. © 2016 RS Software (India) Ltd. 22 Solution in Hive Multiple key Create table list_bucketed_table (c1 string, c2 int, c3 int) skewed by (c1, c2) on ((‘a’, 10), (‘b’, 20)) stored as directories; The metastore will have mapping like (‘a’, 10)->1 , (‘b’,20) ->2 , others -> 3. Select c1, c2, c3 from list_bucketed_table where c1=’a’ and c2=10; The Hive query will use the file from directory (‘a’,10) -> 1
  • 23. © 2016 RS Software (India) Ltd. 23 Solution in Hive Multiple key Create table list_bucketed_table (c1 string, c2 int, c3 int) skewed by (c1, c2) on ((‘a’, 10), (‘b’, 20)) stored as directories; The metastore will have mapping like (‘a’, 10)->1 , (‘b’,20) ->2 , others -> 3. Select c1, c2, c3 from list_bucketed_table where c1=’a’ and c2=10; The Hive query will use the file from directory (‘a’,10) -> 1
  • 24. © 2016 RS Software (India) Ltd. 24 Solution in Hive Advantages: • Each partition’s skewed keys accounts for a significant percentage of the total data. In the above scenario if skewed keys 10,20 and 30 occupy significant portion of the data then queries of the form x=40 will need not require to scan the remaining portion of the data. • The number of skewed keys per partition is small. Since this list is stored in metastore, so it does not make sense to store very large number of keys per partition in the metastore.
  • 25. © 2016 RS Software (India) Ltd. 25 Solution in Hive Disadvantages: • The approach is not scalable when the number of skewed keys is very large. This creates a problem for metastore capability. • It is also not scalable suited when number of skewed keys is more than 1 but in the query all the keys are not specified. • It will not give desired result when skewed keys occupy very less percentage of the total data.
  • 26. © 2016 RS Software (India) Ltd. 26 Solution in Hive Disadvantages: • The approach is not scalable when the number of skewed keys is very large. This creates a problem for metastore capability. • It is also not scalable suited when number of skewed keys is more than 1 but in the query all the keys are not specified. • It will not give desired result when skewed keys occupy very less percentage of the total data.
  • 27. © 2016 RS Software (India) Ltd. 27 Solution in Pig Skewed Join • Skew join works by first sampling one input for the join. • Skew join is capable of identifying that it will not be able to fit the entire input into memory hence, splits them into two reducers. • For all records except those identified in the sample, it does a standard join, collecting records with the same key onto the same reducer. • The second input is the one that is sampled and have its keys with large number of values split across reducers. The first input will have those values replicated across reducers.
  • 28. © 2016 RS Software (India) Ltd. 28 Solution in Pig For example, Employee= load ‘employee’ as (name:chararray, city:chararray); Citydetails= load ‘employee’ as (city: chararray, population: int); Joinop= join Citydetails by city, users by city using ‘skewed’; Suppose the distribution is as follows: 20 users live in Bangalore 10000 users live in Kolkata, 300 users live in Chennai.
  • 29. © 2016 RS Software (India) Ltd. 29 Solution in Pig • Let us assume that Pig determined that 7500 records could be fitted into memory. • If we don’t use skew Pig will throw OutOfMemory exception • But with the use of skew it will separate users with Kolkata as key into two reducers.
  • 30. © 2016 RS Software (India) Ltd. 30 Solution in Pig Memory Usage • Pig looks at the record sizes in the sample and assumes it can use 30%(default) of the JVM’s heap to materialize records that will be joined. • Memory should be decreased if the join is still failing due to out-of-memory errors even using skew join. • So you should tell it to use less.
  • 31. © 2016 RS Software (India) Ltd. 31 Solution in Pig Memory Usage Memory allocation can be configured manually using the following configuration pig.skewedjoin.reduce.memusage=0.25 It can be passed from command line also -D pig.skewedjoin.reduce.memusage=0.25 This will use 25% instead of 30%.
  • 32. © 2016 RS Software (India) Ltd. 32 Thanking You! For further assistance and explanation in anything related to Big Data feel free to mail me at ayanray089@gmail.com