Improving performance of Taste using DBCP

April 25, 2007 – 3:18 am

For the past few weeks I’ve been playing with Taste, a Java based framework for collaborative filtering (basically the recommendation feature found on sites like Amazon and Netflix).    Hopefully in the near feature this tool will be incorporated in our site, MyFriendSuggests.com to improve our suggestion algorithms. 

What I found was the initial description of using a MySQL DataSource sounded fine, but do to the heavy access to the database performance was bad.  Actually it would stop being able to find new connections since the connections were being grabbed faster than windows was cleaning up open sockets.  Simple solution to this was to use the Apache DBCP for db connection pooling.  All I needed to do was add commons-dbcp and commons-pool to my class path and then create a simple function:

public static DataSource getDataSource()
{
  BasicDataSource md =
new BasicDataSource();
  md.setDriverClassName(
“com.mysql.jdbc.Driver”); 
  md.setUrl(
“jdbc:mysql://localhost:3306/dbname”);
  md.setUsername(
“user”);
  md.setPassword(
“pass”);
  return md;
}

I call this method in the constructor of the MySQLJDBCDataModel class.  After doing that things started performing much better.

java MyFriendSuggests taste Technorati Web 2.0

Post a Comment