Sunday, February 15, 2015

Branching for test,staging and production

This document in intended for source version controlling for Test Env,Stag Env and Prodcution Env

List of things that need to be done
Creating Production Branch
Creating Stag  Branch
Creating development branch
Creating a tags (Not Described)
Creating a separate developer branch(Not Described)

Acess Policies in Branches

How to merge in branches

How activities  goes .

Developer
Developer will be using master branch only.They are unaware of stag branch and production branch.They will not be using any other operation other than pull,commit and push.This master branch has mapping with test env on GCE.Everything that is done on master branch is fresh cloned  on test env and tested thoroughly

Tester:After tester has passed the test then system admin is notified to merge master branch to staging.He will be only doing following operations in his local system.
Merging stage branch with origin/master
Step1:First of all clone stage branch .

Step2:Do not directly merge .Make a pull.You will get origin/master branch.

Step3:Now make a Merge .Select origin/master in Remote tracking .Do not select othere branch other than origin/master .Use default system selected merge options and fast forward options
Step4:Push Branch.

Staging branch has mapping with staging env in GCE.Now clone the staging branch in GCE in staging env .

If there is no any bug and error on staging then again it is merged with production branching .The steps are similar for merging stage with production branching .

Merging prodcution branch with origin/stage

Step1:First of all clone prodcution branch .

Step2:Do not directly merge .Make a Pull.You will get origin/stage branch.

Step3:Now make a merge .Select origin/stage in Remote tracking .Do not select othere branch other than origin/stage .Use default system selected merge options and fast forward options.
Step4:Push Branch.

Caching in JPA and Hibernate

* (it symbolises used configuration in Easy-framework)
**(It symbolises default configuration of the provider)


Secondary Cache
Hibernate Secondary Cache
Jpa Secondray Cache (*)
CacheConcurrencyStrategy


Query Cache
Hibernate Query Cache
Jpa Query Cache(*)
storeMode


CacheConcurrencyStrategy  for Secondary cache
READ_ONLY
NONSTRICT_READ_WRITE
READ_WRITE(**) (*)
Transactional
None

Store Mode for secondary cache
USE (*) (**)
BYPASS
REFRESH

Monitoring and Verification Mechanism
View from jvisualvm tool under Mbeans tab under Hibernate list with jmx value of following
SecondLevelCachePutCount
SecondLevelCacheHitCount
SecondLevelCacheMissCount
QueryCachePutCount
QueryCacheHitCount
QueryCacheMissCount

Configuration
If you want to enable query specific  caching  add following in Entity case
@Cacheable
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY, region="com.easy.framework.model.access.AccessRulePolicy")
hints={@QueryHint(name="org.hibernate.cacheable",value="true")}

Configuring Parameter for Load Testing in Production

Samples: Samples denote to the number of http request.
 Average: Average is the average response time for that particular http request. If there are 1000 samples in application then  if 2333 is average time.Then for 1000 samples average time is 2333.This value is in milliseconds.Same for min and max

Min: Min denotes to the minimum response time taken by the http request.If   for 1000 samples  the minimum response time is 266 ms. It means one http request responded in 266 ms out of 1000 samples .


Max: Max denotes to the maximum response time taken by the http request. If   for 1000 samples  the max  response time is 1100 ms. It means one http request responded in 1100 ms out of 1000 samples
Error %: This denotes the error percentage in samples during run.
Throughput : The throughput number represents the actual number of requests/minute the server handled. It is supposed to represent the load on the server .

Latency:
The time from just before sending the request until the request has been processed (request and reply assembly). In short, this should be a more accurate time from a user experience view than the elapsed field which is the time from when the request is sent until a response is received.
Response time (= Sample time = Load time = Elapsed time) is a difference between time when request was sent and time when response has been fully received.
So Response time always >= latency.

Ramp –Up Period :
For example
Number of threads(users) = 11
Ramp up period(in seconds) =  110
Loop Count = 1
110/11=10second
In Every 10 second(110/11) one request hits the server.
Starts with one request initially
Number of threads(users) = 11
Ramp up period(in seconds) = 660
Loop Count = 1
Every 60 second(660/11) one request hits the server
Starts with one request initially
Number of threads(users) = 11
Ramp up period(in seconds) = 660
Loop Count = 3
Every 60 second(660/11) 3 request hits the server
Starts with 3 request initially.

Schedular:Start and end time upto which load testing is performed.It is combined with ramp up period and loop count to simulate real  environment.

Configuring Tomcat,Connection Pooling,JVM , MySql and Monitoring Application Server in Production

Tomcat Server Configuration
Connector
There are two types of connector available AJP Connectors and http connector. AJP Connectors is for load balancing if cluster is required  with apache server configuration .This AJP  configuration is for very large system which runs lots of tomcat clusters .
Used Connector: Http Connector. This time we are using http connector.
Protoc0l
org.apache.coyote.http11.Http11Protocol - blocking Java connector(For large load it is not suitable)
org.apache.coyote.http11.Http11NioProtocol - non blocking Java connector(less threads more connection  NIO  is used, suitable for large load )
org.apache.coyote.http11.Http11AprProtocol - the APR/native connector-Does not use java implementation .Use platform  native interface using  JNI .High performance but required more configuration .
Configuration Used
Used Protocol: org.apache.coyote.http11.Http11NioProtocol
Why used: Default of max 200 threads and minimum of 10 threads simultaneously can accept default of 10000 connections.
According to mathematics use by tomcat.
Tomcat for 200 threads creates 10000 connections by default.
For one connection =200 /10000
For N no of connection=200/10000 Multiply N
So depending on the no of user increasing we will need to change its value for no of connection and no of threads.
Connection Timeout: Used 20000 sec(equivalent to 4 min)
-1 to indicate no (i.e. infinite) timeout.



DB configuration   Parameter:
The min and max size  of connection pooling should be less than My SQL  max no of connection.
Configuration Used
MY SQL max no of connection:500
Connection pooling min size connection :50
Connection Pooling Max size connection:150
Connection Timeout: 0(It means it does not time out).
Connection validation :Enabled. If connection has remained idle for 28690 sec.Then connection is validated after that  time. The term validation mean connection if it has reached idle for 8 hours then MYSQL does not accept that connection after it has reached 8 hours. So, new connection has to be recreated from the pool to replace that expired connection. This feature is controlled by following property
prop key="hibernate.c3p0.idle_test_period">28690</prop><prop key="hibernate.c3p0.preferredTestQuery">select 1</prop>

maxIdleTime: 1800sec.It is configured with following property
<prop key="hibernate.c3p0.timeout">1800</prop>
If 150 is the max pool connection and 50 is the minimum pool  connection. At some instance suppose 100 users concurrently hit the system. Then there is always minimum of 50 connections  available in pool .But, to serve 100 users more connection is required. So, pool created more 50 connections. Suppose all 100 users completed successfully. Now there is 100 connections already created in pool. So, if this property is configured then after 1800 sec it will remove all connections that exceeded  minimum connection .So, it mean after 1800 sec  50 connection will be removed and as always 50 connections are always available in pool.





As, no of user increases connection pooling  min size and max size need to be increased .But the value should be less than MY SQL  max no of connection it allows .Otherwise it throws exception .
Connection pooling  min size  < MY SQL max no of connection
Connection Pooling Max size < MY SQL max no of connection
JVM Configuration Parameter
Based  on java -XX:+PrintCommandLineFlags -XX:+PrintGCDetails –version command and VisaulGC plugin
Heap space and Perm Germ Space.
-Xms3g –Xmx3gm -XX:PermSize=1g -XX:MaxPermSize=1g -XX:+DisableExplicitGC
Normal Consideration is that
Max heap = Min heap(Equal keeps low garbage collector pausing )
Max Perm =Min perm((Equal keeps low garbage collector pausing )


As Perm Germ also is also sub divided into following
PSYoungGen (Survivor 0 area shown in visualvm  with Visual GC Plugin   )
Eden space ((Survivor 1 area shown in visualvm  with Visual GC Plugin   )
ParOldGen
The sum of PSYoungGen+ Eden space + ParOldGen =Heap Space

First Garbage collection starts from PSYoungGen .Survived object on PSYoungGen  is moved to Eden space  .Similarly in Eden space also garbage collection goes on .Again the object that has survived in Eden space  is again moved to ParOldGen  .So,at last in ParOldGen full garbage collection goes on if there is no more space available .










Garbage Collector:
Java provides 3 types of algorithm selection to application listed as follows .
The G1 Garbage Collector
 The Concurrent Mark Sweep (CMS) Collector
 The Parallel GC

Java Garbage collection is designed for two category of application need. What is much important to application  whether  Responsiveness  or Throughput. Depending on need of application algorithm can be switched.
Responsiveness
Throughput
Note: This  is the most advance option for tuning .We can consider this option  later on for garbage collector selection  .

MySQL Configuration:
wait_timeout
connect_timeout
default command timeout

Configuration  on tomcat
<Executor name="easyThreadPool"
            namePrefix="easy-"
            maxThreads="300"
            minSpareThreads="50"
         
  />

<Connector port="80" protocol="org.apache.coyote.http11.Http11NioProtocol" connectionTimeout="240000" redirectPort="443" executor="easyThreadPool" />

    <Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="240000" executor="easyThreadPool"
               SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS"
  keystoreFile="path/to/keystroke.jks " keystorePass="somepassword"
  />
Configuration  on setclasspath.sh
export JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms4536m -Xmx4536m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=856m -XX:+DisableExplicitGC -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.rmi.port=9998 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.0.1"

Configuration on  sql
wait_timeout:120
max_allowed_packet:5511729

Configuration used on connection Pooling
 <prop key="hibernate.c3p0.acquire_increment">25</prop>
<prop key="hibernate.c3p0.idle_test_period">100</prop>
<prop key="hibernate.c3p0.max_size">250</prop>
<prop key="hibernate.c3p0.max_statements">100</prop>
<prop key="hibernate.c3p0.min_size">50</prop>
<prop key="hibernate.c3p0.preferredTestQuery">select 1</prop>
<prop key="hibernate.c3p0.testConnectionOnCheckout">true</prop>

Configuration used for Transaction
<property name="defaultTimeout" value="400" />



Monitoring From Local System using visualvm on GCE
Jstat configuration is already done on GCE.So,the server administation has to follow some more steps
Step 1: sudo ./jstatd -J-Djava.security.policy=jstatd.all.policy -J-Djava.rmi.server.hostname=192.168.0.1
Step 2: Run  "sudo netstat -nlp | grep jstatd"
Step 3:Open port for Jstat.
Step 4:Connect from local visualvm with IP and port
Step 5:Enable JMX on tomcat by adding following in setENV
-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.rmi.port=9998 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.0.1"