Question

I am developing a HTTP application server using Netty 4 and JDBC(+BoneCP for connection pooling).

So far, I am doing all the work(works involving database connections, HttpAsyncClient and so on) on one handler. I close all I/O after each job is finished.

As far as I know, Netty performs well as long as nothing is blocking the worker thread.

However, I read that JDBC connections create blocking I/O.

Is there a good practice to use JDBC with Netty to improve scalability and performance?

Was it helpful?

Solution 2

Make sure you have enough database connections, obviously your workers will block waiting for a connection if your pool is out of connections. The worker will be waiting for a new connection (if the pool is allowed to grow), or waiting for a connection to return otherwise. Otherwise, use general best practices. Tune your reads with setFetchSize() and your writes by using batching. Minimize your round trips, and fetch only the data you need. Do you have specific code (or a query) that is slow?

OTHER TIPS

As you may know, Netty provides EventExecutorGroup to start a separate thread. Blocking calls (e.g. JDBC connections, etc.) should be done in this thread instead of the one with event loop running, so that the main event loop won't be blocked and keeps responsive.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top