How To Configure Tomcat With NIO Connector

Monday, September 21, 2015

How To Configure Tomcat With NIO Connector :-


In HTTP 1.1, all connections between the browser and the server are considered persistent unless declared otherwise. Persistence, in this context, means to use a single TCP connection to send and receive multiple HTTP requests/responses, as opposed to opening a new connection for every single request/response pair.

In tomcat, the default HTTP connector is blocking and follows a one thread per connection model. This means that in order to serve 100 concurrent users, it requires 100 active threads. We end up wasting resources (the thread) because connections may not be used heavily, but just enough to avoid a timeout.

Opposed to this is the relatively new NIO or non blocking connector. This connector has a couple of poller threads used to keep the connection alive for all connected users while worker threads are called whenever data (a new HTTP request) is available. This model leads to a much better sharing of resources (threads) and a larger number of concurrent users can be served from the same server.

In order to configure tomcat to use the Non-blocking NIO connector instead of the default blocking BIO one simply change the value of the protocol attribute of the connector tag in the server.xml from HTTP/1.1 to org.apache.coyote.http11.Http11NioProtocol

<Connector connectionTimeout="20000" maxThreads="1000" port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectPort="8443"/>

To verify that you indeed are using the NIO connector, take a look at the startup logs. check below logs.

Mar 22, 2015 15:50:04 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Mar 22, 2015 15:50:04 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector

Use VisualVM to look at the threads being created in both cases. You’ll find NIO to use threads much more efficiently.



Read more...

Export Data From MongoDB to Mysql Via Csv

How To Export Data From MongoDB to Mysql Via Csv :-

There is no direct way to export MongoDB to Mysql i couldn't find any direct way but here is steps to export data from MongoDB To Mysql.

Step 1:- Export mongo to csv
             >mongoexport --db --collection --csv --fields [,,] --out .csv

Step 2:- Create the mysql database  skeleton
             mysql> CREATE  TABLE   ( VARCHAR(512)[, VARCHAR(512),...]);

Step 3:- Import Csv to mysql
              >mysqlimport -u -p --local --fields-optionally-enclosed-by='"' --fields-terminated-by=',' --lines-terminated-by='\n' --ignore-lines=1 desired_mysql_table_name.csv
         

Read more...

Log all queries in mysql while tomcat start

Friday, September 4, 2015

Log all queries in mysql while tomcat start :-

to log all mysql queries in database while tomcat start. we have to do below steps:-

Step 1.  Create log tables on mysql :-
         
  CREATE TABLE `slow_log` (
   `start_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP 
                          ON UPDATE CURRENT_TIMESTAMP,
   `user_host` mediumtext NOT NULL,
   `query_time` time NOT NULL,
   `lock_time` time NOT NULL,
   `rows_sent` int(11) NOT NULL,
   `rows_examined` int(11) NOT NULL,
   `db` varchar(512) NOT NULL,
   `last_insert_id` int(11) NOT NULL,
   `insert_id` int(11) NOT NULL,
   `server_id` int(10) unsigned NOT NULL,
   `sql_text` mediumtext NOT NULL,
   `thread_id` bigint(21) unsigned NOT NULL
  ) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log'
  CREATE TABLE `general_log` (
   `event_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
                          ON UPDATE CURRENT_TIMESTAMP,
   `user_host` mediumtext NOT NULL,
   `thread_id` bigint(21) unsigned NOT NULL,
   `server_id` int(10) unsigned NOT NULL,
   `command_type` varchar(64) NOT NULL,
   `argument` mediumtext NOT NULL
  ) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='General log'

Step 2. Enable Query logging on mysql database :-
            SET global general_log = 1;
            SET global log_output = 'table';

Step 3. View logs on mysql
           select * from mysql.general_log

Step 4. Disable Query logging on mysql DB :-
            SET global general_log = 0;

Step 5. Check Count Of Queries :-
            select left(argument,50), count() from general_log group by left(argument,50) order by count() desc limit 50;



Read more...

Enable Slow Query Log in MySQL without restart Mysql

Friday, June 19, 2015

Enable Slow Query Log in MySQL without restart Service

there are below steps :-

root in [~]# touch /var/log/mysql-slow.log
root in [~]# chown mysql:mysql /var/log/mysql-slow.log
root in [~]# mysql -e 'SET GLOBAL slow_query_log=1;'
root in [~]# mysql -e 'SET GLOBAL slow_query_log_file="/var/log/mysql-slow.log";'
root in [~]# mysql -e 'SET GLOBAL long_query_time=2;'

Read more...

How to automatically restart Apache on system reboot time ?

Saturday, February 28, 2015

How to automatically restart Apache on system reboot time ?

To Start Apache at Boot Time, need to do below process. The Apache server is started as root because it uses port 80 (lower than 1024) but it spawns processes that run as "nobody".

Save the following script as /etc/init/apache. it will automatically be read and run at boot time. Check the log files if it does not start properly.

Make a link to it from /etc/rc5.d such as:
cd /etc/rc5.d
sudo ln -s ../init.d/apache S72apache

----------------------------  /etc/init.d/apache  ------------------------
#!/bin/bash
#
# apache        
#
# chkconfig: 
# description:  Start up the Apache web server.

# Source function library.
. /etc/init.d/functions


RETVAL=$?
APACHE_HOME="/usr/apps/apache/apache"

case "$1" in
 start)
 if [ -f $APACHE_HOME/bin/apachectl ]; then
     echo $"Starting Apache"
        $APACHE_HOME/bin/apachectl start
    fi
 ;;
 stop)
 if [ -f $APACHE_HOME/bin/apachectl ]; then
     echo $"Stopping Apache"
        $APACHE_HOME/bin/apachectl stop
    fi
  ;;
 *)
  echo $"Usage: $0 {start|stop}"
 exit 1
 ;;
esac

exit $RETVAL
-----------------------  end of /etc/init.d/apache  ----------------------

Read more...

How to automatically restart Tomcat on system reboot time ?

How to automatically restart Tomcat on system reboot time ?

There are 2 method:-

Method 1. Create the init script in /etc/init.d/tomcat with following lines :-

#!/bin/sh
# chkconfig: - 80 20
# Created by: USer
# Purpose: Start or stop the Tomcat service.
# Check the path of Tomcat and set enviorment variables as follows in the .bashrc profile
# chkconfig: 345 99 01
#chkconfig: 2345 50 70
# export CATALINA_HOME="/usr/local/tomcat7/apache-tomcat-7.0.37"
# export CATALINA_BASE="/usr/local/tomcat7/apache-tomcat-7.0.37"
# export JAVA_HOME="/usr/local/java/jdk1.7.0_17"
#export JAVA_HOME="/usr/java/jdk1.5.0_15"
export JAVA_HOME="/usr/java/jdk1.6.0_25"
case $1 in
start)
cd /usr/local/tomcat/bin/
./startup.sh
;;
stop)
cd /usr/local/tomcat/bin/
./shutdown.sh
;;
restart)
cd /usr/local/tomcat/bin/
./shutdown.sh
cd /usr/local/tomcat/bin/
./startup.sh
;;
esac
exit 0

--------------------

Change its permissions and add the correct symlinks automatically:-
chmod 755 /etc/init.d/tomcat7
update-rc.d tomcat7 defaults


Method 2:-
user should be valid "tomcat" and has rw permissions in the $CATALINA_HOME/conf and $CATALINA_HOME/logs directories. and $JAVA_HOME shpuld be proper set. You will start Tomcat as user "tomcat" to avoid running it as root.

Save the following script as /etc/init.d/tomcat . it will automatically be read and run at boot time. Check the log files if it does not start properly.

Make a link to it from /etc/rc5.d such as:

cd /etc/rc5.d
sudo ln -s ../init.d/tomcat S71tomcat

----------------------------  /etc/init.d/tomcat  ------------------------
#!/bin/bash
#
# tomcat      
#
# chkconfig:
# description: Start up the Tomcat servlet engine.

# Source function library.
. /etc/init.d/functions


RETVAL=$?
CATALINA_HOME="/usr/local/tomcat/jakarta-tomcat-6"

case "$1" in
 start)
        if [ -f $CATALINA_HOME/bin/startup.sh ];
          then
   echo $"Starting Tomcat"
            /bin/su tomcat $CATALINA_HOME/bin/startup.sh
        fi
;;
 stop)
        if [ -f $CATALINA_HOME/bin/shutdown.sh ];
          then
   echo $"Stopping Tomcat"
            /bin/su tomcat $CATALINA_HOME/bin/shutdown.sh
        fi
  ;;
 *)
  echo $"Usage: $0 {start|stop}"
exit 1
;;
esac

exit $RETVAL
-----------------------  end of /etc/init.d/tomcat  ----------------------











Read more...

About This Blog

Lorem Ipsum

  © Copyright 2009 Linux-HelpLine.Blogspot.com

Back to TOP