java - Accessing a mapper's counter from a reducer -
I need to access the counters from my Maper in my reducers. Is this possible? If so, how is it done?
As an example: My Mapper is:
Public square counter mapper and text text, text, text, text & gt; {Static enum TestCounters {TEST} @ Override throws the protected Zero map (text key, text value, reference reference) IOException, interrupted; Exception {context.getCounter (TestCounters.TEST). Construction (1); Context.write (key, value); }} is my reducer
extends the public square CounterReducer Reducer & lt; Text, Text, Text, Longway & gt; {@Override Reduces Safe Zero (text key, iterable & lt; text & gt; values, reference references) throws IOException, interrupted; Exception {counter counter = context.getCounter (CounterMapper.TestCounters.TEST); Long counter value = counter .getValue (); Context.write (key, new long countervalue); }} counterValue is always 0. Am I doing something wrong or is it not possible?
In Reducer's Configurable (JobConf), you see the reducer's own Job ID for the JobConf object With this, your rediscover can create your own job client for job tracker - that is, ask counters for this job (or any work for that matter).
// Reduce class ... Private Long Mapper Cropper; @ Override Public Waste Configured (JobConf Config) {JobClient Client = New JobClient (conf); RunningJob parentJob = client.getJob (JobID.forName (conf.get ("mapred.job.id"))); MapperCounter = parentJob.getCounters (). GetCounter (MAP_COUNTER_NAME); } You can now use the mapper control within the least () method.
You really need a try-catch. I am using the old API, but should not be friendly to the new API.
Note that before the start of any reducer the mappers counter should be finalized, so unlike Justin Thomas's comment, I believe that you should get the exact price (unless the reducer Not equal counter counters!)
Comments
Post a Comment