public static int getSupervisorPortNum ( Map conf , int sysCpuNum , Long physicalMemSize ) { double cpuWeight = ConfigExtension . getSupervisorSlotsPortCpuWeight ( conf ) ; int cpuPortNum = ( int ) ( sysCpuNum / cpuWeight ) ; if ( cpuPortNum < 1 ) { LOG . info ( "Invalid supervisor.slots.port.cpu.weight setting :" + cpuWeight + ", cpu cores:" + sysCpuNum ) ; cpuPortNum = 1 ; } Double memWeight = ConfigExtension . getSupervisorSlotsPortMemWeight ( conf ) ; int memPortNum = Integer . MAX_VALUE ; if ( physicalMemSize == null ) { LOG . info ( "Failed to get memory size" ) ; } else { LOG . debug ( "Get system memory size: " + physicalMemSize ) ; long workerMemSize = ConfigExtension . getMemSizePerWorker ( conf ) ; memPortNum = ( int ) ( physicalMemSize / ( workerMemSize * memWeight ) ) ; if ( memPortNum < 1 ) { LOG . info ( "System memory is too small for Jstorm" ) ; memPortNum = 1 ; // minimal port number set to 1 if memory is not enough } } return Math . min ( cpuPortNum , memPortNum ) ; }
calculate port number from cpu number and physical memory size