12. Request Player

C-JDBC comes with a tool called 'Request Player' that allows to replay queries that have been recorded using the logging facility of the controller. This is useful for both debugging and performance tuning.

12.1. Recording a request trace

There is a specific logger in the log4j.properties configuration file is located in the /c-jdbc/config directory of your installation. To learn more about configuring the log report to Section 6.4, “Configuring the Log”. To turn on the request tracing, update your log4j.properties with the following logger declaration:

# To trace requests #
log4j.logger.org.objectweb.cjdbc.controller.VirtualDatabase.request=INFO, Requests
log4j.additivity.org.objectweb.cjdbc.controller.VirtualDatabase.request=false
      

The trace file is stored as defined in the logger definition. Here is the default definition that is shipped with C-JDBC:

log4j.appender.Requests=org.apache.log4j.RollingFileAppender
log4j.appender.Requests.File=request.log
log4j.appender.Requests.MaxFileSize=100MB
log4j.appender.Requests.MaxBackupIndex=5
log4j.appender.Requests.layout=org.apache.log4j.PatternLayout
log4j.appender.Requests.layout.ConversionPattern=%d{ABSOLUTE} %c{1} %m\n
      

You can set the trace file name (you can also provide a path) in the log4j.appender.Requests.File property. The log4j.appender.Requests.MaxFileSize property defines the maximum trace file size. Finally, log4j.appender.Requests.MaxBackupIndex defines the number of trace files that will be generated. For example, in the above configuration, the trace will be made of 5 files of 100MB.

The file format expected by the request player is as follows:

date virtualDatabaseName requestType transactionId SQL

requestType is B for begin, S for select statements, W for write statements (insert, update, delete, create, drop), C for commit and R for rollback.

Here is an example of a trace of transaction n?27562:

10:34:22,775 tpcw B 27562
10:34:22,776 tpcw S 27562 select count(*) from shopping_cart_line where scl_sc_id = 424
10:34:22,778 tpcw S 27562 select i_related1 from item where i_id = 5759
10:34:22,779 tpcw S 27562 select scl_qty from shopping_cart_line where scl_sc_id = 424 and scl_i_id = 4903
10:34:22,781 tpcw W 27562 insert into shopping_cart_line (scl_sc_id, scl_qty, scl_i_id) values (424,1,4903)
10:34:22,782 tpcw W 27562 update shopping_cart set sc_time = now() where sc_id = 424
10:34:22,783 tpcw S 27562 select * from shopping_cart_line, item where scl_i_id = item.i_id and scl_sc_id = 424
10:34:22,787 tpcw C 27562
      

12.2. Replaying a trace file

The Request Player allows you to replay a trace file conforming to the format described in the previous section. The Request Player behavior is defined in a property file. The default property file is requestplayer.properties located in the /c-jdbc/config directory of your installation. The format of this file is described in Section 12.3, “requestplayer.properties”.

The bin directory of the C-JDBC distribution contains the scripts to start the Request Player. Unix users must start the controller with requestplayer.sh whereas Windows users will use requestplayer.bat. These scripts accepts the following options:

  • -h or --help displays a help message.

  • -f or --file followed by the property file name. If this option is omitted, the default file is requestplayer.properties located in the /c-jdbc/config directory of your installation.

  • -v or --version displays version information.

12.3. requestplayer.properties

The Request Player properties file defines the following properties:

  • db_driver: Database driver class (an example is org.objectweb.cjdbc.driver.Driver).

  • db_url: Database JDBC URL (an example is jdbc:cjdbc://localhost/test).

  • db_username: the login to use to connect to the database.

  • db_password: the password to use to connect to the database.

  • trace_file: the full path and name of the request trace file to replay (an example is /tmp/request.log).

  • nb_requests: the number of requests to replay or 0 if the full trace file has to be played. Note that once the specified number of requests has been reached, all opened transactions are played by the player until they finish. Therefore, there might be more requests executed than the number specified in this property.

  • nb_clients: number of emulated clients that will issue the requests in parallel (number of threads in the player).

  • timeout: request timeout in seconds, a value of 0 meaning no timeout.

  • connection_type: any value in standard, fixed or pooling. If standard is chosen, a new connection is used for each transaction or for each non transactionnal request to execute. If fixed is chosen, one connection is dedicated to each client thread for the whole run. If pooling is set, connection pooling is used.

  • poolsize: size of the pool if connection_type has been set to pooling.