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...

About This Blog

Lorem Ipsum

  © Copyright 2009 Linux-HelpLine.Blogspot.com

Back to TOP