protected int getMaxSlots ( JobConf conf , int numCpuOnTT , TaskType type ) { int maxSlots ; String cpuToSlots ; if ( type == TaskType . MAP ) { maxSlots = conf . getInt ( "mapred.tasktracker.map.tasks.maximum" , 2 ) ; cpuToSlots = conf . get ( "mapred.tasktracker.cpus.to.maptasks" ) ; } else { maxSlots = conf . getInt ( "mapred.tasktracker.reduce.tasks.maximum" , 2 ) ; cpuToSlots = conf . get ( "mapred.tasktracker.cpus.to.reducetasks" ) ; } if ( cpuToSlots != null ) { try { // Format of the configuration is // numCpu1:maxSlot1, numCpu2:maxSlot2, numCpu3:maxSlot3 for ( String str : cpuToSlots . split ( "," ) ) { String [ ] pair = str . split ( ":" ) ; int numCpu = Integer . parseInt ( pair [ 0 ] . trim ( ) ) ; int max = Integer . parseInt ( pair [ 1 ] . trim ( ) ) ; if ( numCpu == numCpuOnTT ) { maxSlots = max ; break ; } } } catch ( Exception e ) { LOG . warn ( "Error parsing number of CPU to map slots configuration" , e ) ; } } return maxSlots ; }
Obtain the max number of task slots based on the configuration and CPU