Showing posts with label emr. Show all posts
Showing posts with label emr. Show all posts

Wednesday, December 13, 2017

EMR Spark duplicating every action and job keeps running

Leave a Comment

I have created a scala application that uses Apache Spark to retrieve data from s3, do some transformation on it and save it.

I am using Apache Spark 2.0.2 configured in a 50 (r3.4xLarge) cluster mode.

hive-env.export HADOOP_HEAPSIZE 8192 spark.executor.cores             5 spark.executor.instances         149 spark.driver.memory              106124M spark.executor.memory            38000M spark.default.parallelism        5000 spark.sql.shuffle.partitions     1000 spark.kryoserializer.buffer.max  1024m  spark.sql.hive.convertMetastoreParquet false spark.hadoop.mapreduce.input.fileinputformat.split.maxsize 2560000000 spark.files.maxPartitionBytes 2560000000 spark.network.timeout            500s 

The job is running for more than 2 days now. Tried changing executor size, memory and al no use. I am seeing in the spark ui -

Active : Stage 0 persist at ItemBuilder.scala:197   Stage 1 persist at ItemBuilder.scala:197  Stage 0 and 1 persists shows : Tasks: Succeeded/Total = 115475/204108  Pending : Stage 2 persist at ItemBuilder.scala:197   Stage 2 persists shows : Tasks: Succeeded/Total =  0/400  Stage 3 count at ItemBuilder.scala:202 Stage 3 count shows : Tasks: Succeeded/Total =  0/200  Stage 4 count at ItemBuilder.scala:202 Stage 4 count shows : Tasks: Succeeded/Total =  0/1 

Can some one tell me why I am seeing persist 3 times ? and count 2 times ?

Here is my code :

val textFiles = sqlSession.sparkContext.textFile( files.mkString( "," ) )  val jsonFiles = sqlSession.read.schema( schema ).json( textFiles )  log.info( "Job is in progress" )  val filteredItemDetails = jsonFiles.filter( col( ITEM_ID ).isNotNull ).filter( length( col( ITEM_ID ) ) > 0 )  val itemDetails = filteredItemDetails.withColumn( ITEMS, explode( filteredItemDetails( ITEMS ) ) )   .filter( size( col(ITEM_EVENTS ) ) > 0 )   .filter( col( ITEM_TIMESTAMP ).isNotNull )   .select( ITEM_ID, EVENTS_ITEM_ENTRY, ITEM_TIMESTAMP )  val convertTimestamp = udf { (timestampString: String) => {     DateUtils.getSqlTimeStamp(timestampString)   } }  val itemDetailsWithTimestamp = itemDetails.withColumn(TIME_STAMP_CONVERTED, convertTimestamp(col(TIME_STAMP)))  val recentTime = DateUtils.getSqlTimeStamp( endTime )  val groupedData = itemDetailsWithTimestamp.groupBy( ITEM_ID, ITEM_ENTRY_ID )   .agg( datediff( lit( recentTime ), max( TIME_STAMP_CONVERTED ) ) as DAY_DIFFERENCE, count( ITEM_ENTRY_ID ) as FREQUENCY )   val toMap = udf { (itemType: String, count: Int) => Map( itemType -> count ) }  val tempResult = groupedData.withColumn( FREQUENT_DAYS, toMap( col( ITEM_ENTRY_ID ), col( DAY_DIFFERENCE ) ) )   .withColumn( FREQUENCY_COUNT, toMap( col( ITEM_ENTRY_ID ), col( FREQUENCY ) ) )   .drop( ITEM_ENTRY_ID )   .drop( DAY_DIFFERENCE )   .drop( FREQUENCY )  val result = tempResult.groupBy( ITEM_ID )   .agg( CombineMaps( col( FREQUENT_DAYS ) ) as FREQUENT_DAYS,     CombineMaps( col( FREQUENCY_COUNT ) ) as FREQUENCY_COUNT )   .persist( DISK_ONLY )   log.info( "Aggregation is completed." )  val totalItems = result.count( )  log.info( "Total Items = " + totalItems ) 

And in the Resource manager I am seeing :

Memory Used = 5.52 TB Memory Total = 5.52 TB Memory Reserved = 113.13 GB VCores Used = 51 VCores Total = 51 VCores Reserved = 1  And Application Queues shows : Used (over capacity) Used Capacity:  101.2% Configured Capacity:    100.0% 

Can some one tell me am I mis configured anything here ? My job is stuck at stage 0 itself.

I tried to test with reducing the data. It works fine then, but I used the original data I keep getting :

org.apache.spark.SparkException: Job aborted due to stage failure: Task 204170 in stage 16.0 failed 4 times, most recent failure: Lost task 204170.4 in stage 16.0 (TID 1278745, ip-172-31-12-41.ec2.internal): ExecutorLostFailure (executor 520 exited caused by one of the running tasks) Reason: Executor heartbeat timed out after 626834 ms Driver stacktrace:   at org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1454)   at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1442)   at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1441)   at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)   at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)   at org.apache.spark.scheduler.DAGScheduler.abortStage(DAGScheduler.scala:1441)   at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:811)   at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:811)   at scala.Option.foreach(Option.scala:257)   at org.apache.spark.scheduler.DAGScheduler.handleTaskSetFailed(DAGScheduler.scala:811)   at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.doOnReceive(DAGScheduler.scala:1667)   at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:1622)   at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:1611)   at org.apache.spark.util.EventLoop$$anon$1.run(EventLoop.scala:48)   at org.apache.spark.scheduler.DAGScheduler.runJob(DAGScheduler.scala:632)   at org.apache.spark.SparkContext.runJob(SparkContext.scala:1873)   at org.apache.spark.SparkContext.runJob(SparkContext.scala:1886)   at org.apache.spark.SparkContext.runJob(SparkContext.scala:1899)   at org.apache.spark.SparkContext.runJob(SparkContext.scala:1913)   at org.apache.spark.rdd.RDD.count(RDD.scala:1134)   ... 242 elided 

I am also seeing :

Dropping SparkListenerEvent because no remaining room in event queue. This likely means one of the SparkListeners is too slow and cannot keep up with the rate at which tasks are being started by the scheduler. 

1 Answers

Answers 1

I believe those are stages of the job and not the actual persist/count happening twice. Stages are group of parallel tasks which can happen at the same time without incurring a shuffle. I see 2 groupBy s in your code which requires shuffle hence the 2 stages. Does that help?

Read More

Monday, September 12, 2016

Amazon EMR: running Custom Jar with input and output from S3

Leave a Comment

I am trying to run an EMR cluster which has a custom jar step. The program takes input from S3 and outputs to S3 (or at least this is what I want to accomplish). In the step configuration, I have the following in the arguments field:

v3.MaxTemperatureDriver s3n://hadoopbook/ncdc/all s3n://hadoop-szhu/max-temp 

where hadoopbook/ncdc/all is the path to the bucket containing the input data (as a side note, the example I'm running is from this book), and hadoop-szhu is my own bucket where I want to store the output. Following this post, my MapReduce driver looks like this:

package v3;  import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner;  import v1.MaxTemperatureReducer;  public class MaxTemperatureDriver extends Configured implements Tool {    @Override   public int run(String[] args) throws Exception {     if (args.length != 2) {       System.err.printf("Usage: %s [generic options] <input> <output>\n",           getClass().getSimpleName());       ToolRunner.printGenericCommandUsage(System.err);       return -1;     }      Job job = new Job(getConf(), "Max temperature");     job.setJarByClass(getClass());      FileInputFormat.addInputPath(job, new Path(args[0]));     FileOutputFormat.setOutputPath(job, new Path(args[1]));      job.setMapperClass(MaxTemperatureMapper.class);     job.setCombinerClass(MaxTemperatureReducer.class);     job.setReducerClass(MaxTemperatureReducer.class);      job.setOutputKeyClass(Text.class);     job.setOutputValueClass(IntWritable.class);      return job.waitForCompletion(true) ? 0 : 1;   }    public static void main(String[] args) throws Exception {     int exitCode = ToolRunner.run(new MaxTemperatureDriver(), args);     System.exit(exitCode);   } } 

However, when I try to run this, I get the following error:

Exception in thread "main" java.io.IOException: No FileSystem for scheme: s3n 

I've also tried to copy the data from s3 to the cluster using the following (run after sshing into the master node):

hadoop distcp \   -Dfs.s3n.awsAccessKeyId='...' \   -Dfs.s3n.awsSecretAccessKey='...' \   s3n://hadoopbook/ncdc/all input/ncdc/all 

But I get a bunch of errors, I've included an excerpt below:

2016-09-03 07:07:11,858 FATAL [IPC Server handler 6 on 43495] org.apache.hadoop.mapred.TaskAttemptListenerImpl: Task: attempt_1472884232220_0001_m_000000_0 - exited : java.io.IOException: org.apache.hadoop.tools.mapred.RetriableFileCopyCommand$CopyReadException: java.io.FileNotFoundException: No such file or directory 's3n://hadoopbook/ncdc/all/1901.gz'     at org.apache.hadoop.tools.mapred.CopyMapper.map(CopyMapper.java:224)     at org.apache.hadoop.tools.mapred.CopyMapper.map(CopyMapper.java:50)     at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:146)     at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:796)     at org.apache.hadoop.mapred.MapTask.run(MapTask.java:342)     at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:164)     at java.security.AccessController.doPrivileged(Native Method)     at javax.security.auth.Subject.doAs(Subject.java:422)     at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1657)     at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158) Caused by: org.apache.hadoop.tools.mapred.RetriableFileCopyCommand$CopyReadException: java.io.FileNotFoundException: No such file or directory 's3n://hadoopbook/ncdc/all/1901.gz'     ... 10 more Caused by: java.io.FileNotFoundException: No such file or directory 's3n://hadoopbook/ncdc/all/1901.gz'     at com.amazon.ws.emr.hadoop.fs.s3n.S3NativeFileSystem.getFileStatus(S3NativeFileSystem.java:818)     at com.amazon.ws.emr.hadoop.fs.EmrFileSystem.getFileStatus(EmrFileSystem.java:511)     at org.apache.hadoop.tools.mapred.CopyMapper.map(CopyMapper.java:219)     ... 9 more 

I'm not sure where the issue lies, but I would be happy to include more details (please comment below). Thanks!

1 Answers

Answers 1

s3n:// is the old protocol, you should instead be using s3://

Reference: http://docs.aws.amazon.com//ElasticMapReduce/latest/ManagementGuide/emr-plan-file-systems.html

Read More

Sunday, April 24, 2016

Pig write to S3 via HCatStorer() “succeeds” with 0-bytes written

Leave a Comment

I created an external Hive (1.0 on EMR) table that is stored in S3. I can successfully use Hive to insert records into this table, query them back, and pull the files directly from the S3 bucket as verification. So far, so good.

I would like to be able to use Pig (v0.14, also on EMR) to both read and write to this logical table. Loading with HCatLoader() works fine, and dump/explain confirm that my data and schema are as expected.

When I try to write with HCatStorer() however, I have problems. Pig reports success, with N records, but 0 bytes, written. I see nothing that seems relevant or indicative of a problem in the log, and no data is written into the table/bucket.

a = load 'myfile' as (foo: int, bar: chararray); // Just assume that this works.  dump a; // Records are there describe a; // Correct schema, as specified above store a into 'mytable' using org.apache.hive.hcatalog.pig.HCatStorer();  

The output (which, again contains no other indication of problems that I can see) concludes with:

Success!  ...  Input(s): Successfully read 2 records (24235 bytes) from: "myfile"  Output(s): Successfully stored 2 records in: "mytable"  Counters: Total records written : 2 Total bytes written : 0 Spillable Memory Manager spill count : 0 Total bags proactively spilled: 0 Total records proactively spilled: 0 

Of note:

  • This works in the same environment if the table location is in HDFS instead of S3 - for both external and internal tables, and from either Hive or Pig.
  • I can successfully store directly to S3 with e.g. store a into 's3n://mybucket/output' using PigStorage(',');
  • An insert via the Hive shell to the same query works fine.

So this appears to be a problem with the interplay of Pig/HCatalog/S3 as a stack; any two of these together seem to work fine.

Given that I don't see anything very useful in the Pig log, what else should I look at to debug this? Are there any particular configuration parameters for any of these technologies that I should look at?

0 Answers

Read More