Sign in to follow this  

Testing my Database pooling?

This topic is 828 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey,

 

I want to test my database pooling so I figured to start queries on a separate thread. This works and I see the active and idle connections increase. But I had just a couple of these threads in line. For some real testing (completely drain the pool and see what happens) I figured to put the thread creation in a loop but this results in having at most 1 active connection and after thread 1 they all finish in 0ms. I have not done much with threads but it's probably not a good idea to create those in a loop.

for (int i = 0; i < 100; i++)
        {
            final int y = i;
            Thread t = new Thread()
            {
                @Override
                public void run() {
                    long start = System.nanoTime();
                    DataSourceExample db = new DataSourceExample();
                    System.out.println("Thead " + (y + 1) + " finished in: " + ((System.nanoTime() - start) / 1000000) + "ms.");
                }
            };
            t.run();
        }

But how can I (stres) test my MySQL database properly? I am using java `import org.apache.commons.dbcp2.BasicDataSource;` to create the pool. I have no experience with testing these.

Share this post


Link to post
Share on other sites
Write a test client app that connects to the server. Then just flood the server with request. If you have more computers do the same and connect all and see what happens.
All you need is a console app with connection and a loop sending to the server.

Share this post


Link to post
Share on other sites
The client library may be caching the connection and pooling it across threads.
Thus, you may need multiple processes, rather than multiple threads, to create more of them.
If you're on Linux, you can easily run a shell for loop to create however many copies you want.
On Windows, I'd probably create a text (.BAT) file that just calls "start java ... MyClass.class ..." and copy-paste that line many times.
"start" is a Windows shell command that runs the given command asynchronously.

Share this post


Link to post
Share on other sites

This topic is 828 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this