🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Testing my Database pooling?

Started by
1 comment, last by hplus0603 8 years, 9 months ago

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.

Advertisement
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.
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.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement