Results 1 to 2 of 2
  1. #1
    newbie14 is offline Member
    Join Date
    Feb 2010
    Posts
    64
    Rep Power
    0

    Default Java and mysql stress test

    I have an a java tcp socket application. Tcp communicator decodes the GPS location and inserts that data into the database and before inserting we do some selects and updates but all I do it using prepared statements. Right now, one thread of TCP communicator serves one device request.Immediately after creating the thread we get one connection from the pool. After decoding the GPS data is where we perform the multiple select, update and insert for each data. As number of devices are increasing, the number of concurrent connections to our Mysql database are also increasing.So I am trying to conduct a simulation and stress test something like below. The issue is that this is sequential test but in real environment the devices will be coming in parallel. How to achieve a near real stress situation for both mysql and java to find out how many inserts could mysql take in on second? Also I would like how to know many sockets connection could java handle?

    Java Code:
    public class stress1 extends Thread {
        public static void main(String[] argv) {
            try {
                for (int i = 0; i < 5000; i++) {
                Socket socket = new Socket("192.168.2.102", 8000);
                PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
                BufferedReader in = new BufferedReader(new InputStreamReader(
                socket.getInputStream()));
                out.println("$A12345,30061104075130528955N10024852E000068*03A1*");
                System.out.println(in.readLine() + i);
                out.close();
                in.close();
                socket.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
           }
          }
        }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    25

    Default Re: Java and mysql stress test

    First off, on a single machine you will need to be launching multiple threads.

    Second, if on a single machine you are not going to get a good simulation as you are really limited to the number of cores on your machine to get a really effective load without the machine switching between threads. But it's a start point.

    So, taking the above, I would shift the above code into a TestConnection class.
    Then the above would become:
    Java Code:
    public class Main {
        public static void main(String[] argv) {
            for (int i = 0; i < 5000; i++) {
                new Thread.start(new TestConnection());
            }
        }
    }
    This, however, could well result in many of the threads finishing before the last one has been created.

    Another option is to create a number of threads equal to cores, and each of those threads keeps creating connections until you tell it to stop (or it's got more than enough running concurrently).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Java DB, MySQL and MySQL Connector/J
    By jimihunter007 in forum JDBC
    Replies: 2
    Last Post: 07-30-2012, 05:23 AM
  2. Replies: 4
    Last Post: 03-04-2012, 11:26 PM
  3. Stress test plugin?
    By thagentleman in forum Eclipse
    Replies: 0
    Last Post: 04-20-2009, 12:03 AM
  4. Replies: 0
    Last Post: 04-05-2008, 12:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •