Thursday, May 31, 2012

Friday, May 18, 2012

Riak vs MongoDB vs MySQL Performance tests 1



Environment 1 
Intel(R) Xeon(R) CPU           X3430  @ 2.40GHz
Cores: 4
8 MB Cache
Memory : 6GB
ulimit : 1024
OS : CentOS 5.4

Riak : 1.1
MySQL 5.1 (Highly tuned system)

Test data :
Object : username, email, id

Both test's were run from Java clients

To make this test little meaningful I've send each read/write command to mysql in its own request.

MySQL Single Node (time in ms)

 inserts : 50, time : 871
 inserts : 100, time : 324
 inserts : 200, time : 835
 inserts : 500, time : 1936
 inserts : 1000, time : 3275


 gets : 50, time : 55
 gets : 100, time : 60
 gets : 200, time : 119
 gets : 500, time : 304
 gets : 1000, time : 582


Riak Single Node (Recommended is 3 Nodes)

 inserts : 50, time : 461
 inserts : 100, time : 486
 inserts : 200, time : 1473
 inserts : 500, time : 3609
 inserts : 1000, time : 6442


 gets : 50, time : 2296
 gets : 100, time : 4501
 gets : 200, time : 9028
 gets : 500, time : 22496
 gets : 1000, time : 44981



Environment 2
Intel(R) Core(TM)2 Duo CPU     P8600  @ 2.40GHz
Cores: 2
Memory : 4GBulimit : 1024
OS : MacOS 10.6


Riak : 1.1
MySQL 5.1 (Highly tuned system)


Test data :
Object : username, email, id (No constraints, No indexes)

To make this test little meaningful I've send each read/write command to mysql in its own request.

MySQL Single Node (time in ms)
 inserts : 50, time : 1606
 inserts : 100, time : 288
 inserts : 200, time : 515
 inserts : 500, time : 1277
 inserts : 1000, time : 2399


 gets : 50, time : 46
 gets : 100, time : 38
 gets : 200, time : 69
 gets : 500, time : 245
 gets : 1000, time : 753



RIAK

inserts : 50, time : 1032 
inserts : 100, time : 1389 
inserts : 200, time : 2555 
inserts : 500, time : 6408 
inserts : 1000, time : 10777

 gets : 50, time : 654 

gets : 100, time : 1308 
gets : 200, time : 2157 
gets : 500, time : 5062 
gets : 1000, time : 8722 


MongoDB
inserts : 150 time: 165
inserts : 10000 time: 2623
inserts : 20000 time: 2128
inserts : 50000 time: 2926
inserts : 100000 time: 5833
inserts : 200000 time: 16862
inserts : 500000 time: 29535
inserts : 1000000 time: 69929 


Database size and count
database  size :  0.953125GB
Object count : 20,83,700


get : 150 time: 58
get : 1100 time: 109
get : 2200 time: 193
get : 3500 time: 768
get : 5000 time: 1977




Test code
https://github.com/intesar/Riak-Perf-1
https://github.com/intesar/MySQL-Perf1 
https://github.com/intesar/MongoDB-Perf1 



Tuesday, May 15, 2012

Simple Log4J Yahoo mail setup to recieve production errors as emails

Receive all server exceptions as email, never miss one, easy to share and discuss with the others

Follow these simple steps to configure Log4j to use Yahoo mail.


Step 1: Add dependencies

        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4</version>
        </dependency>
      
        <!-- Log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
        </dependency>


Step 2: Sample logging file, inline comments are self explanatory
        file linke : https://github.com/intesar/Log4jYahoo/blob/master/src/main/resources/log4j.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
        <!-- Appends events to console : compliments SMTPAppender -->
        <appender name="Console" class="org.apache.log4j.ConsoleAppender">
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="[${name}] - %d{ISO8601} - %X{login} - %m%n" />
            </layout>
        </appender>

        <!-- will only sends error events -->
        <appender name="Email" class="org.apache.log4j.net.SMTPAppender">
            <param name="BufferSize" value="1" /> <!-- default is 512, changed for test cases to work -->
            <param name="SMTPProtocol" value="smtps" /> <!-- log4j 1.2.16 is required -->
            <param name="SMTPHost" value="smtp.mail.yahoo.com" />
            <param name="SMTPPort" value="465" />
            <param name="SMTPUsername" value="intesar@ymail.com" /> <!-- example@gmail.com -->
            <param name="from" value="intesar@ymail.com" /> <!-- required -->
            <param name="SMTPPassword" value="" /> <!-- passowrd -->
            <param name="To" value="mdshannan@gmail.com" /> <!-- required -->
            <param name="Subject" value="Zytoon.me Error Log" />
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="[${name}] - %d{ISO8601} - %X{login} - %m%n" />
            </layout>
        </appender>

        <appender name="EMAIL_ASYNC" class="org.apache.log4j.AsyncAppender">
            <param name="BufferSize" value="1"/>
            <appender-ref ref="Email"/>
        </appender>

        <root>
            <priority value="trace" />
            <!-- use Email appender for local test to pass -->
            <appender-ref ref="EMAIL_ASYNC" />
            <appender-ref ref="Console" />
        </root>

    </log4j:configuration>



Sample Code

    import org.apache.log4j.Logger;

    public class App {

        private static Logger logger = Logger.getLogger(App.class);

        public static void main(String[] args) throws InterruptedException {

            logger.trace("trace message");

            logger.warn("warn message");

            // only error msgs will be emailed
            logger.error("error message, a very long error message!");

            Thread.sleep(2000);
        }
    }


fork it https://github.com/intesar/Log4jYahoo

Monday, May 14, 2012

Simple setup Log4j with GMail and recieve all errors as email

Receive all server exceptions as email, never miss one, easy to share and discuss with the others

Follow these simple steps to configure Log4j to use GMail.


Step 1: Add dependencies

        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4</version>
        </dependency>
      
        <!-- Log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
        </dependency>


Step 2: Sample logging file, inline comments are self explanatory
        https://github.com/intesar/Log4jGmail/blob/master/src/main/resources/log4j.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
       
        <!-- Appends events to console : compliments SMTPAppender -->
        <appender name="Console" class="org.apache.log4j.ConsoleAppender">
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="[${name}] - %d{ISO8601} - %X{login} - %m%n" />
            </layout>
        </appender>

        <!-- SMTP will only log error events -->
        <appender name="Email" class="org.apache.log4j.net.SMTPAppender">
            <param name="BufferSize" value="1" /> <!-- default is 512, changed for test cases to work -->
            <!-- GMail will not work without this, log4j 1.2.16 is required this why earlier versions required hack-->
            <param name="SMTPProtocol" value="smtps" />
            <param name="SMTPHost" value="smtp.gmail.com" />
            <param name="SMTPPort" value="465" />
            <param name="SMTPUsername" value="<email>" /> <!-- example@gmail.com -->
            <param name="SMTPPassword" value="<passowrd>" /> <!-- passowrd -->
            <param name="To" value="mdshannan@gmail.com" />
            <param name="Subject" value="Zytoon.me Error Log" />
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="[${name}] - %d{ISO8601} - %X{login} - %m%n" />
            </layout>
        </appender>

        <appender name="EMAIL_ASYNC" class="org.apache.log4j.AsyncAppender">
            <param name="BufferSize" value="1"/>
            <appender-ref ref="Email"/>
        </appender>

        <root>
            <priority value="trace" />
            <appender-ref ref="Email" />
            <appender-ref ref="Console" />
        </root>

    </log4j:configuration>


Sample Code

    import org.apache.log4j.Logger;

    public class App {

        private static Logger logger = Logger.getLogger(App.class);

        public static void main(String[] args) throws InterruptedException {

            logger.trace("trace message");

            logger.warn("warn message");

            logger.error("error message, a very long error message!");

            Thread.sleep(2000);
        }
    }

Fork it on Github https://github.com/intesar/Log4jGmail

Sunday, May 13, 2012

Simple reusable GMailJava class for sending Aysnc emails via Gmail


Simple reusable GMailJava class for sending Aysnc emails. Copy the class, change the username/password and use it in your next project. 
   Step 1: Add dependencies to your maven project
<!-- mail --> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4</version> </dependency> <!-- Apache Commons Validator --> <dependency> <groupId>commons-validator</groupId> <artifactId>commons-validator</artifactId> <version>1.4.0</version> </dependency> Step 2: Copy EmailService.java to your project & set username/password code: https://github.com/intesar/GMailJava/blob/master/src/main/java/com/bia/gmailjava/EmailService.java Note: Enable pop, IMAP inside GMail --> Settings --> Forwarding and POP / IMAP

    Sample code

      EmailService emailService = EmailService.getInstance();
      emailService.sendEmail("<toemail>", "<subject>", "<body>");

    Design Decisions
     No interface is define to keep simpler eco-system, feel free to add yours if required and refactor code accordingly
     Pattern's & Technique's used - Singleton, Command, Async, Inner class
Also you can clone it on github https://github.com/intesar/GMailJava



Send emails using Yahoo


Simple reusable YahooMailJava class for sending Aysnc emails via Yahoo. Copy the class, change the username/password and use it in your next project. 
 Step 1: Add dependencies to your maven project
<!-- mail --> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4</version> </dependency> <!-- Apache Commons Validator --> <dependency> <groupId>commons-validator</groupId> <artifactId>commons-validator</artifactId> <version>1.4.0</version> </dependency> Step 2: Copy YahooMailService.java to your project and set username/password
    code: https://github.com/intesar/YahooMailJava/blob/master/src/main/java/com/bia/yahoomailjava/YahooMailService.java
Sample code YahooMailService emailService = YahooMailService.getInstance();
      emailService.sendEmail("<toemail>", "<subject>", "<body>");
Design Decisions No interface is define to keep simpler eco-system, feel free to add yours if required and refactor code accordingly Pattern's & Technique's used - Singleton, Command, Async, Inner class

fork it on github or copy the required classes https://github.com/intesar/YahooMailJava

GMailJava class for sending Async emails


Simple reusable GMailJava class for sending Aysnc emails. Copy the class, change the username/password and use it in your next project. 
   Step 1: Add dependencies to your maven project
<!-- mail --> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4</version> </dependency> <!-- Apache Commons Validator --> <dependency> <groupId>commons-validator</groupId> <artifactId>commons-validator</artifactId> <version>1.4.0</version> </dependency> Step 2: Copy EmailService.java to your project & set username/password code: https://github.com/intesar/GMailJava/blob/master/src/main/java/com/bia/gmailjava/EmailService.java Sample code EmailService emailService = EmailService.getInstance(); emailService.sendEmail("<toemail>", "<subject>", "<body>"); Design Decisions No interface is define to keep simpler eco-system, feel free to add yours if required and refactor code accordingly Pattern's & Technique's used - Singleton, Command, Async, Inner class
Also you can clone it on github https://github.com/intesar/GMailJava




Saturday, May 12, 2012

Free website monitor service and seo


 Website Uptime Monitor Service is a really nice simple service to monitor websites for free, No registration or signup is required, just put the site url, email and start monitoring. Few other features they plan to offer.

Free  Features!
1. Site/Web Service Monitor 
2. Email Alerts 
3. Weekly reports 
4. Checkout site uptime status anytime
5. SEO & Social Media coverage on Twitter, G+, FB, Pinterest, Blogger, Reddit for 95+ percent uptime!


They also have Android, iOS, Window's Mobile Apps also their site is compatible with all major smart phones.

Here is their website...
 http://www.zytoon.me/monitor