Jmeter test database read performance - jmeter

I am going to test database read performance with Jmeter Java Sampler.
Basically, query database 10000 times with primary key as query condition like ID with Thread group and Java Sampler.
I need to load 10000 records into database before executing the Thread Group.
The 10000 records will be looped for the 10000 times database read.
I have looked into the preprocessor of Jmeter. I can insert 10000 records into database in preprocessor, but I do not know how to pass the 10000 IDs to Thread Group or Java Sampler. It is too long to contact IDs as a String parameter.
How I can archive the purpose? Any comment is welcome.

Instead of inserting the data using PreProcessor I would rather recommend preparing the test data in setUp Thread Group. You can write the generated IDs into a file using i.e. Flexible File Writer and then read them back with the CSV Data Set Config
If the database you're testing supports JDBC protocol it makes more sense to use JDBC Request sampler because JDBC Connection Configuration allows using connection pool pattern which most probably your application will be using when talking to the database, the main idea is to set up JMeter to produce the same footprint as the application which will be accessing the database.

Related

Return from query that refers tables in two different db

I have a goal where I need to write a query in JDBC postprocessor of JMeter but the tables used in query are in different databases. Some tables are in Db2 and others are in PostgreSQL.
I can connect and get response from two databases i.e. Db2 and PostgreSQL separately. However when I write query, that refer to tables in different db, I see relationship doesn't exist error.
I understand, I can use bound pool variables in JMeter for different db connections.
My question:
How can I use these bound pool variables, which are referring to different db (Db2 and PostgreSQL) connection in JMeter, in a single query, if that is possible. Maybe an example will help here, please?
If what I mention in 1 is not possible in JMeter, then how can I achieve above mentioned overall goal through JMeter?
It is not possible either "through jmeter" or "through" any other database client.
If you need to execute 2 separate queries at the same time - you can add 2 JDBC Connection Configuration elements for 2 databases, 2 JDBC Request samplers and a Synchronizing Timer.

JdbcBatchItemWriterBuilder vs org.springframework.jdbc.core.jdbcTemplate.batchUpdate

I understand jdbcTemplate.batchUpdate is used for sending several records to data base in one communication.
Lets say i have 1000 records to be updated, instead of 1000 communications from Application to database, the Application will send 1000 records in request.
Coming to JdbcBatchItemWriterBuilder its combination of Tasks in a job.
My question is, if there is 1000 records to be processed(INSERT statements) via JdbcBatchItemWriterBuilder, all INSERTS executed in one go? or one after one?
If one after one, connecting to database 1000 times using JdbcBatchItemWriterBuilder causes perf issues? hows that handled?
i would like to understand if Spring batch performs better than running 1000 INSERT staments using jdbcTemplate.update ?
The JdbcBatchItemWriter uses java.sql.PreparedStatement#addBatch and java.sql.Statement#executeBatch internally (See https://github.com/spring-projects/spring-batch/blob/c4010fbffa6b71cbcfe79d523023251ce73666a4/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcBatchItemWriter.java#L189-L195), so there will be a single batch insert for all items of the chunk.
Moreover, this will be executed in a single transaction as described in the Chunk-oriented Processing section of the reference documentation.

JMeter Refer to two different databases in one Test Plan

I want tо refer to two different databases in one sql server in my Test Plan.
I have one Thread Group and 20 steps/samplers, and I want for the first 4 samplers all queries to database to be connect to 'database1' for example and others from step 5 to step 20 all queries are refered to 'database2'.
When I add JDBC connection configuration and try to change dynamically just DatabaseName JMeter accepts the first filled databaseName. For example: If I filled first 'database1' as a name all my connections to databases are to this 'database1' independently from that I change the value of DatabaseName adding new value of the variable 'database'.
I use something like:
jdbc:sqlserver://something.database.windows.net;DatabaseName=${database}
JDBC connection configuration is loaded once before test executed, as other JMeter's configurations
So you must have 2 JDBC connection configurations for each database with 2 different variable names
In JDBC request you can use different variable name when using different database pool names

Can JMeter JDBC pre-processor accept multiple Insert/delete/update queries?

Can JMeter JDBC pre-processor accept multiple Insert/delete/update queries?
I have added two queries:
JMeter can do whatever underlying JDBC driver can do, for example for MySQL you can specify allowMultiQueries JDBC URL parameter and you will be able to separate statements by semicolon.
Looking into oracle pool variable name my expectation is that you're trying to test an Oracle database and its JDBC driver doesn't support this feature.
The options are in:
Create a stored procedure which will delete multiple records
Parameterize existing JDBC PreProcessor using i.e. __StringFromFile() function, in this case you will not have to copy and paste the preprocessors
Use JSR223 PreProcessor instead of the JDBC PreProcessor and implement your records deletion logic there, take a look at Statement.addBatch() function, you can combine multiple queries into one statement with it. Check out Using Statement Objects for Batch Updates chapter of the Retrieving and Modifying Values from Result Sets article for more details.
You can submit multiple queries as is, because you can't use ; in JDBC request
But you can use other techniques to insert/delete multiple records, for example using IN
delete from CPAY where bnf_nic_name in ('BillerBBJ929' ,'BillerOFV864')

How to pass a unique id stored in database to HTTP request in JMeter

In my JMeter script, When I save equipment detail using HTTP REQUEST then a unique auto incremented id(Suppose 123) store in database. Then in same script when I am adding Incentive on previously saved equipment then in it's HTTP REQUEST that unique ID(123) is passing. Since that ID is fetching from database so I am unable to get that.
Initially I was thinking to use a COUNTER and start it from a high number which is not stored in database but it didn't work because it requires same ID which generated at the time of savings the equipment.
I created my JMeter script using HTTP(S) TEST SCRIPT RECORDER.
To connect to database you need JDBC Connection Configuration and to define database connection properly, Then you need to add JDBC Element as JDBC PreProcessor (or Sampler), and add your select of this id, Query Type: Select Statement, Query will be for example select sequnceName.NEXTVAL from dual in oracle DB, you can put sequence result in a Result variable name,for example mySequence and use it later in JSR 223 element:
columnValue = vars.getObject("mySequence").get(0).get("NEXTVAL");
So you can extract the ID generated in the "Equipment Detail" Request/Response and save it in an external .csv file using JSR223 Post processor and use the .csv file for "Incentive" request.
This way you can eliminate database calls and your scripts run only for HTTP Requests with less turnaround time.

Resources