Pages

Monday, July 21, 2014

how to find the linux os and version

type uname -a for the linux version
type lsb_release -a for the os details

Tuesday, July 1, 2014

Java EE singleton pitfall

If you implement a singleton class with the @Singleton annotation, then it is  considered all the method level access is read and write. Therefore a write lock is established automatically. Which is not good. Since when a method required a read lock its default setting is a write lock. So when you are programming, then you should always keep that in mind.

Wednesday, June 4, 2014

MySQL clustering(NDB) vs MySQL replication (InnoDB)

MySQL InnoDB

InnoDB often comes with master/slave configuration. The drawback of this method is writes are only on master and the slaves provide only reads. Therefore concurrent writes are not supported unless you use a mechanism called shading. 

What happens when a database grows so that it cannot handle in one database and a server. Then comes the shading option. But it has to be done very carefully in order to not to lose  performance. If you want to scale out the system for write operations, using this storage mechanism, then you need to use the shading option.

shading for reads

  1. when the data set do not fit into the memory and consists of may read hits from the disk rather than serving from memory.

shading for writes

  1. when there are too many writes that the replication lags considerably.
  2. the frequency of writes is overloading this servers disks permanently

How ever if you are going for the option of sharding, it is always good to have application level sharding. The reason is, when the application knows where the data resides, the performance becomes better.

Sharding types

  1. application level sharding - put the most busy tables into separate servers and access them.
  2. sharding by hash key
  3. sharding using a lookup service

Why sharding is one of the last options?

  1. developer has to write code to handle the shading logic
  2. backup, indexing, changing schema makes it more difficult to maitain

MySQL clustering

MySQL clustering how ever supports concurrent writes. Data is partitioned among the data nodes and a copy of a node or a backup is in another node. Therefore availability is assured. 

How ever the problem is even though it provides foreign key join supports the process is slow since the data is partitioned in several nodes. If the join operation results in large volume of data this could be slow. Therefore tasks such as generating reports that takes usually several minutes are not good to be implemented using this method. Also another thing to note in this method is, it supports concurrent writes.

Setting up MySQL clustering can be more tedious than setting up InnoDB. But still it prevents the developer from using shading, since the partitioning happens among the nodes.

Below is a link which provides some hints on how to increase the performance in a mysql cluster

https://blogs.oracle.com/MySQL/entry/mysql_cluster_performance_best_practices




Wednesday, April 23, 2014

ActiveMq message broker

Some userfull links I found on ActiveMQ

http://www.slideshare.net/dejanb/advanced-messaging-with-apache-activemq#btnNext
http://working-with-activemq.blogspot.com/2012/05/performance-improvements.html
http://www.javacodegeeks.com/2014/04/activemq-network-of-brokers-explained.html

Monday, April 21, 2014

Some very important links to be read for distributed computing

http://en.wikipedia.org/wiki/X/Open_XA
http://fusesource.com/documentation/fuse-esb-documentation/
http://activiti.org/components.html
http://servicemix.apache.org/
https://www.mulesoft.com/resources/esb/mule-esb-integration-platform

Tuesday, April 8, 2014

Scaling a relational database

Below are the highlights I saw from the valuable article given in the following link.

http://java-persistence-performance.blogspot.com/2011/05/data-partitioning-scaling-database.html

 So hats off to the author who outlined these valuable things.

You can take 5 steps to scale a database

  1. optimizing the number and types of queries hitting the database, using parametrized SQL, using batch writing, using lazy, join and batch fetching, a significant load can be removed from the database.
  2. ensuring your database is configured optimally, has the correct indexes, queries are using the optimal query plan, and the disk access optimally, its performance, and thus scalability can be improved
  3. caching objects and data in the mid-tier, you can offload a lot of the queries hitting the database, and improve your application's performance to boot. Most JPA providers support caching, and some such as EclipseLink offer quite advanced caching functionality including invalidation, and coordinated clustered caches. JPA 2.0 defines some basic caching annotations to enable and access the cache.
  4. scale the database through clustering the database across multiple machines. This could be a real clustered database, such as Oracle RAC, or just multiple regular database instances. Clustered database are good, and can improve your scalability without much work, but depending on your application you may also have to partition your data across the database nodes for optimal scalability. Without partitioning, if you write a row on one node, then access it on another, the other node must request the latest copy of the data from the other node, this can potentially make performance worse.
  5. partitioning data across each of the database nodes
Data partitioning can be done in 2 major ways
  • Vertical partitioning
  • Horizontal partitioning

Sunday, April 6, 2014

How to use log4j with your own configuration in jboss 7.1.1?

The following link describes this problem

http://stackoverflow.com/questions/10799028/jboss-7-1-logging-is-not-working

Monday, March 31, 2014

Exchange types in an AMQP messaging protocol

There are several types of exchanges in AMQP protocol

  • fanout - messages are published to all queues
  • direct - messages are delivered if the message's routing key is identical to the queue's binding key.
  • topic - The exchange routes messages to the relevant queue or queues, depending on matches between the routing and binding keys
  • header - headers of the messages, and the binding key constraints of the queues are used to determine the correct queue/queues
A good article about the above is explained in detail in the following article.

Friday, March 28, 2014

RabbitMQ commands

To check the status of the RabbitMQ issue
sudo rabbitmqctl status

To stop the message broker issue,
sudo rabbitmqctl stop

To restart the message broker issue,
sudo invoke-rc.d rabbitmq-server start

Thursday, March 27, 2014

HazelCast --> what is hazel cast?

Today I looked at HazelCast and wrote some code using the library. I found this library to be extremely useful and simple. Some of the advantages found in hazelcast are,
  1. It can be used as a No-SQL data store - http://www.hazelcast.org/use-cases/in-memory-nosql/
  2. Useful for messaging (pub/sub, topics etc...) - http://www.hazelcast.org/use-cases/messaging/
  3. Can be used as a data-grid - http://www.hazelcast.org/use-cases/data-grid/
  4. Can be used for caching - http://www.hazelcast.org/use-cases/caching/
  5. For application scaling - http://www.hazelcast.org/use-cases/application-scaling/
  6. For clustering sessions in java web apps - http://www.hazelcast.org/use-cases/clustering/

Tuesday, March 18, 2014

How to install mysql on jboss as a module

first create the folder structure <jboss directory>/modules/com/mysql/main
copy the the mysql connector jar to the folder
thlen add module.xml file to the same folder and add the following to the module.xml

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.mysql">
  <resources>
     <resource-root path="mysql-connector-java-5.1.28.jar"/>            
  </resources>
  <dependencies>
     <module name="javax.api"/>
  </dependencies>
</module>

Note that the resource-root element's path should be the file name of the mysql connector jar

Now the final step

edit the standalone.xml file in standalone/configuration folder. then add the following in the drivers element.
<driver name="mysqlDriver" module="com.mysql">
                        <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
                    </driver>

note the mysqlDriver is the name of the driver and you can use it to configure the data source.

Thursday, March 13, 2014

clustering

clustering an application enables apps to scale out and cater a large audience. most renowned servers supports this feature. when one node goes down other nodes are present to cater the user requests. but what happens to the session of the server which went down? well the session replication across the cluster becomes very important in this case. if you take jboss, it replicates using messages. tomcat also supports it when it is clustered and uses a communication framework called Tribes to achieve it.

A simple how to cluster and do session replication with jboss can be found in the following article.

https://docs.jboss.org/author/display/AS71/AS7+Cluster+Howto?_sscc=t

Usefull maven test commands


some usefull maven commands can be found in the following link

http://kishanthan.wordpress.com/2012/04/30/useful-maven-commands/

What is integrating testing

Integration testing is test to verify that an external service call responds correctly to your input data.

if a test uses

  • the database
  •  an external system (e.g. a queue or a mail server)
  • a test reads/writes files or performs other I/O
  • the network
it is normally an integration test. Arquillian is a popular testing framework that supports integration testing.

How to do maven unit tests

to test the app simply issue the following command

mvn test

to run a single test issue

mvn -Dtest=<test class name> test

to skip unit testing while building  issue put the following directive to your maven goal

-Dmaven.test.skip=true


Tuesday, March 4, 2014

jersy vs apache cxf

Well jersy is a simple framework for REST full web services. Usage of it is pretty straight forward. Apache cxf is better if you need to work with SOAP web services. It all depends on what protocol you like to use. if REST then jersy works well while for SOAP apache cxf does the job.

Another thing to notice is that SOAP uses WSDL and the equivanlent of it in REST world is WADL. But still WADL is not standardized.

http://en.wikipedia.org/wiki/Web_Application_Description_Language.

For more info read the following article.

http://stackoverflow.com/questions/2704700/java-rest-implementation-jersey-vs-cxf

A simple resutfull implementation with jersy is described in the below article.

http://www.vogella.com/tutorials/REST/article.html

Thursday, February 27, 2014

Tomcat DOS attack vulnerability

Tomcat by default supports multipart mime types.  For this purpose it uses apache commons fileupload library. However when there is a request longer then approximately 4 kb, tomcat goes to an endless loop which finally causes a high usage of cpu resources. This vulnerability is present in tomcat 7 and 8 versions only and there are patches that can be applied manually.

http://www.javacodegeeks.com/2014/02/apache-tomcat-and-denial-of-service-vulnerability.html

Thursday, February 20, 2014

What is jenkins?

Read the article

https://wiki.jenkins-ci.org/display/JENKINS/Meet+Jenkins

Sunday, February 16, 2014

Optimistic locking

What is optimistic locking? Imagine two users read data at the same time and both of them do updates. Then the last to update will win. that is the normal situation.

So how would you handle this situation without compromising the concurrency of the system. The below article gives one solution to this using spring read it carefully.

http://camelcase.com.au/public/jpa/optimistic-locking-with-jpa-and-spring/

Wednesday, February 12, 2014

What is declarative security?

Declarative security is the means of securing an application by means of deployment descriptors.
In ejb world it could be in ejb-jar.xml which is in META-INF folder. In web applications it could be in web.xml file in WEB-INF folder.

Monday, February 10, 2014

java version configuration in ubuntu

to set default java version in your machine type in the terminal,

sudo update-alternatives --config java

there you will get a prompt and then you can set it.

to set java home globally follow the instructions add the following lines in the .barshrc file which is located in the /home/yourusername/ directory

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
PATH=$PATH:JAVA_HOME