3.1 TokenStore on PostgreSQL

Got my app up and running under 3.1 well enough to start doing some benchmarking/profiling runs. One hot spot that immediately jumped out in the profiler was JdbcTokenStore.insertOrUpdateToken(). It seems that updating a ResultSet is quite slow in the PostgreSQL JDBC driver; under the hood, for each field modification, the JDBC driver ends up querying the table metadata from the database to find out the table's primary key so it can construct a plain UPDATE statement which it then executes. It doesn't appear to cache the table metadata across queries, plus the three resultSet.update*() calls in that method end up causing three separate metadata lookups and three separate UPDATEs.

Subclassing JdbcTokenStore to override that method and replace it with a plain "UPDATE TokenStore SET token = ?, tokenType = ?, timestamp = ? WHERE processorName = ? AND segment = ?" gave me an immediate 13% throughput gain on my app as a whole in my test environment. I got another 5% gain from doing the same thing to claimToken().

It's quite likely this is database-specific and that on other databases, it's faster to update a ResultSet. And the benefit will vary depending on the number of tracking processors in the app. But for Postgres, at least, there's an easy win here.

-Steve

Hi Steven,

thanks for sharing this! Given that the query is pretty straightforward (and compatible on all databases), it’s probably better to not rely too much on Driver specific optimizations of the ResultSet updating.
Is your change shareable/suitable for a PR?

Cheers,

Allard