Calculating memorypool sizes

I have chosen some values from these guidelines from Charlie Hunt’s book. This is the latest ‘R’ code. That last blog entry has the old code.

I am using some of these general rules just as a foundation for further calculation. Generally our capacity planning teams do not have any baseline. I have not investigated the actual justification for some of these figures.

Guidelines for Calculating Java Heap Sizing

Java heap - 3x to 4x old generation space occupancy
after full garbage collection

Permanent Generation - 1.2x to 1.5x permanent generation space
occupancy after full garbage collection

Young Generation - 1x to 1.5x old generation space
occupancy after full garbage collection

Old Generation Implied from overall Java heap size minus the young
generation size

2x to 3x old generation space occupancy
after full garbage collection


library(stringr)

this.dir <- dirname(parent.frame(2)$ofile) 
setwd(this.dir)

data <- read.table("D:\\GC Analysis\\gc.log-node1",sep="\n")

parse.mean <- function(){
	fullgc.timestamp( fullgc.read() )
}


# Grep Full GC lines
fullgc.read <- function(){
	return (data$V1[ grep ("(.*)Full GC(.*)", data[,1])])
}

fullgc.data <- function(timedata,memorydata){

   memorydata["Time"] <- "NA"
   memorydata$Time <- unlist(timedata)
   return (fixdate(memorydata))
}

fullgc.timestamp <- function(input){

	time <- str_extract(input,"T[^.]*")
	timeframex<-data.frame(time)
	timeframey<-subset(timeframex, timeframex[1] != "NA")
	timeframey<-substring(timeframey$time,2,9)
	timeframey <- data.frame(timeframey)
	colnames( timeframey ) <- c("Time")
    return (timeframey)	
}

fullgc.memorypool.mean <- function(input){
	data <- str_extract(input,"PSYou.*[/)]")
	data <- str_extract_all(data,"[0-9]+")
	data <- data.frame(matrix(unlist(data),ncol=12,byrow=T))
	colnames(data)[2] <- c("YoungGenAfterFullGC")
	colnames(data)[8] <- c("OldGenAfterFullGC")
	colnames(data)[11] <- c("PermGenAfterFullGC")
    return (data)
}

fixdate <- function(filtereddata){

    filtereddata$Time1<-strptime(filtereddata$Time,"%H:%M:%S")
	offset<-86400
    lasttime<-filtereddata$Time1[1]
    
	filtereddata$Time1[1]<-filtereddata$Time1[1]+offset
	lasttime<-filtereddata$Time1[1]
	for(timedate in 2:length(filtereddata$Time1)) {
		if(as.numeric(filtereddata$Time1[timedate]) < lasttime){
			offset<- offset + 86400
		}
		filtereddata$Time1[timedate]<-filtereddata$Time1[timedate]+offset
		lasttime<-filtereddata$Time1[timedate]
	}
	return(filtereddata)
}

fullgc.youngandoldgen.graph <- function(filtereddata){
	print(filtereddata)
	png(
	"younggenrecommendation.png",
	width =1700, height = 510)
options("scipen"=100, "digits"=4)    
plot( filtereddata$Time1,
      levels(filtereddata$YoungGenAfterFullGC)[filtereddata$YoungGenAfterFullGC],
	  col="darkblue",type="l",
	  ylab="MB",
	  xlab="",
	  las=2,
	  lwd=5.5,
	  cex.lab=1,
	  cex.axis=0.8,
	  xaxt="n",
	  ylim=c(min(as.numeric(levels(filtereddata$OldGenAfterFullGC)[filtereddata$OldGenAfterFullGC])),
	         max(as.numeric(levels(filtereddata$OldGenAfterFullGC)[filtereddata$OldGenAfterFullGC]))))
axis(1, at = as.numeric(filtereddata$Time1), labels = filtereddata$Time, las = 2,cex.axis=1.2)
mtext("Time", side=1, line=-1, cex=1.3) 
abline(h=mean(as.numeric(levels(filtereddata$OldGenAfterFullGC)[filtereddata$OldGenAfterFullGC])),col="yellow")
title("Younggen(1.5*Mean of Oldgen) and Total heap(4 * oldgen mean) recommendation",cex.main=1.5)
	box("figure", col="blue")
points( filtereddata$Time1,
        levels(filtereddata$OldGenAfterFullGC)[filtereddata$OldGenAfterFullGC],
		col="yellow",
		las=2,
		lwd=5.5,
		type="l")
legend("topleft", lty=c(1,1),lwd=c(3.5,3.5),
       c(paste("Younggen = Oldgenmean * 1.5 = ",
	            signif(mean(as.numeric(levels(filtereddata$OldGenAfterFullGC)[filtereddata$OldGenAfterFullGC]))/1048*2,digits=2)," "," * 1.5 = ",
				signif((mean(as.numeric(levels(filtereddata$OldGenAfterFullGC)[filtereddata$OldGenAfterFullGC]))/1048*2)*1.5,digits=2),"MB"),
				paste("Total heap ",signif((mean(as.numeric(levels(filtereddata$OldGenAfterFullGC)[filtereddata$OldGenAfterFullGC]))/1048*2)*4,digits=2),"MB")),
 	   fill=c("darkblue"))

dev.off()
}

fullgc.permandoldgen.graph <- function(filtereddata){

	png(
	"permgenrecommendation.png",
	width =1700, height = 510)
options("scipen"=100, "digits"=4)    
plot( filtereddata$Time1,
      levels(filtereddata$PermGenAfterFullGC)[filtereddata$PermGenAfterFullGC],
	  col="darkblue",type="l",
	  ylab="MB",
	  xlab="",
	  las=2,
	  lwd=5.5,
	  cex.lab=1,
	  cex.axis=0.8,
	  xaxt="n",
	  ylim=c(min(as.numeric(levels(filtereddata$OldGenAfterFullGC)[filtereddata$OldGenAfterFullGC])),
	         max(as.numeric(levels(filtereddata$OldGenAfterFullGC)[filtereddata$OldGenAfterFullGC]))))
axis(1, at = as.numeric(filtereddata$Time1), labels = filtereddata$Time, las = 2,cex.axis=1.2)
mtext("Time", side=1, line=-1, cex=1.3) 
abline(h=mean(as.numeric(levels(filtereddata$OldGenAfterFullGC)[filtereddata$OldGenAfterFullGC])),col="yellow")
abline(h=mean(as.numeric(levels(filtereddata$PermGenAfterFullGC)[filtereddata$PermGenAfterFullGC])),col="darkblue")
title("Permgen(1.5*mean)/Oldgen(2*mean)  recommendation",cex.main=1.5)
	box("figure", col="blue")
points( filtereddata$Time1,
        levels(filtereddata$OldGenAfterFullGC)[filtereddata$OldGenAfterFullGC],
		col="yellow",
		las=2,
		lwd=5.5,
		type="l")
legend("topleft", lty=c(1,1),lwd=c(3.5,3.5),
       c(paste("Oldgen ",signif((mean(as.numeric(levels(filtereddata$OldGenAfterFullGC)[filtereddata$OldGenAfterFullGC]))/1048*2)*2,digits=2),"MB"),
	     paste("Permgen ",signif((mean(as.numeric(levels(filtereddata$PermGenAfterFullGC)[filtereddata$PermGenAfterFullGC]))/1048*2)*1.5,digits=2),"MB")),
 	   fill=c("darkblue","yellow"))

dev.off()
}

permgenrecommendation

younggenrecommendation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: