Jmeter-JDBC request wait till have result - jmeter

I am trying to run the performance script which has API which takes the payload as file from S3 and submit to target system. After the request is completed I need to login to db and verify the status of the transaction. Here there is delay in getting inserted to db which is fast for payload with small file size. As I started submitting large files 1 GB to 15 GB, there will be delay in inserting a table.
So the JDBC request which has modified_date will be null for large payload. I have used constant timer but not sure how long it takes to insert in table.
Is there any way I can make jdbc request to wait till i get result for modified_date for message table.

You can put your JDBC Request sampler under the While Controller and use i.e. following jexl3() function as the condition:
${__jexl3("${modified_date}" == "null",)}
Once done you can use the Constant Timer for introducing the reasonable delay, i.e. run the JDBC Request each second or several seconds until the result is there.
More information: Using the While Controller in JMeter

Related

How Spring - server.connection-timeout will work internally?

I'm little confused on how the server.connection-timeout property will work on a spring boot REST API project
I have a Spring boot REST API Project in which I have a delete REST API, this will basically do couple of delete operation on a Database table say for example this delete API will delete some rows on 3 tables as following
Delete API gets "customer Id" as Input and execution the following
Delete all records matching the customer Id in Table A (delete call to an external DB)
Delete all records matching the customer Id in Table B (delete call to an external DB)
Delete all records matching the customer Id in Table C (delete call to an external DB)
my question here is if I set "server.connection-timeout" to 5 Seconds what does it actually means?
I have 2 two assumptions
The delete Rest Api will timeout in 5 Seconds meaning all the 3 external DB call has to be done within the 5 Seconds if not the REST API will timeout
Each external DB call will have 5 Seconds timeout, in this case 15 Seconds totally
In worst case if all the 3 External DB call takes 4 Seconds then the Delete API will take 12 Seconds to respond - is this a valid one?
I think you are confusing. server.connection-timeout – is the time that connectors wait for another HTTP request before closing the connection.
It doesn't matter how much time it takes to complete the request.
In your case if server.connection-timeout is 5, this will not effect #1 #2 or #3 deletes which you mentioned.
In a simple terms connection-timeout does not apply to long running requests. Instead It applies to the initial connection, when the server waits for the client to request something.
Default: the connector’s container-specific default is used. Use a value of -1 to indicate infinite timeout.

JMeter: How to benchmark data deletion from database table in batches?

I am trying to compare the performance difference between DELETE batch sizes using JMeter.
I have a table which I populate with a large amount of test data. Next, I have a JDBC Request that runs the following statement:
delete from tbl where (entry_dt < '2019-02-01') and (rownum <= 10000);
I want to keep running this until the table is empty, and record the time taken to clear the table.
I will run this thread multiple times to get an average execution time, and repeat this process for different batch sizes.
How should I define my While Controller to achieve this?
I read from other sites that I can use a Transaction Controller to time my process, but I am not familiar with this feature. How should I define my Transaction Controller to achieve this?
Add Transaction Controller to be a top level test element under the Thread Group
Add While Controller as a child of the Transaction Controller and use the following condition expression:
${__jexl3(${count_1} > 0,)}
Put your JDBC Request sampler as a child of the While Controller
Add JDBC PostProcessor as a child of the JDBC Request sampler and configure it like:
That's it, While Controller will iterate until there are entries in the tbl table and the Transaction Controller will record the cumulative time of all JDBC Request samplers executed.
I would do it this way:
Use the "JDBC Request - Get Count" sampler to get the data from the db which has to be deleted
Use a BeanShell Assertion to check if there is more data that can be deleted. Otherwise stop the thread
Execute the request to delete the data
Thread Group should stop Test on error

Spring #Transactional + Isolation.REPEATABLE_READ for Rate Limiting

We are trying a scenario of Rate Limiting the total no. of JSON records requested in a month to 10000 for an API.
We are storing the total count of records in a table against client_id and a Timestamp(which is primary key).
Per request we fetch record from table for that client with Timestamp with in that month.
From this record we get the current count, then increment it with no. of current records in request and update the DB.
Using the Spring Transaction, the pseudocode is as below
#Transactional(propagation=Propagation.REQUIRES_NEW, isolation=Isolation.REPEATABLE_READ)
public void updateLimitData(String clientId, currentRecordCount) {
//step 1
startOfMonthTimestamp = getStartOfMonth();
endOfMonthTimestamp = getEndOfMonth();
//step 2
//read from DB
latestLimitDetails = fetchFromDB(startOfMonthTimestamp, endOfMonthTimestamp, clientId);
latestLimitDetails.count + currentRecordCount;
//step 3
saveToDB(latestLimitDetails)
}
We want to make sure that in case of multiple threads accessing the "updateLimitData()" method, each thread get the updated data for a clientId for a month and it do not overwrite the count wrongly.
In the above scenario if multiple threads access the method "updateLimitData()" and reach the "step 3". First thread will update "count" in DB, then the second thread update "count" in DB which may not have latest count.
I understand from Isolation.REPEATABLE_READ that "Write Lock" is placed in the rows when update is called at "Step 3" only(by that time other thread will have stale data). How I can ensure that always threads get he latest count from table in multithread scenario.
One solution came to my mind is synchronizing this block but this will not work well in multi server scenario.
Please provide a solution.
A transaction would not help you unless you lock the table/row whilst doing this operation (don't do that as it will affect performance).
You can migrate this to the database, doing this increment within the database using a stored procedure or function call. This will ensure ACID and transactional safety as this is built into the database.
I recommend doing this using standard Spring Actuator to produce a count of API calls however, this will mean re-writing your service to use the actuator endpoint and not the database. You can link this to your Gateway/Firewall/Load-balancer to deny access to the API once their quote is reached. This means that your API endpoint is pure and this logic is removed from your API call. All new API's you developer will automatically get this functionality.

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.

How to create database connection in Http Request Sampler in Jmeter

I am new to JMeter. I want to make MySQL connection to database so I can calculate the time that took to upload an audio and it is inserted in the database. I am trying to upload audio to my API and when the audio uploads then it go for background processing and then it is inserted in database. I am doing load testing when I hit this API it returns success when it go for background processing. But I want to calculate time taken by when I upload audio and it is inserted in database. How can I do it?
I would do it as follows:
Transaction Controller - to measure time of all nested samplers
HTTP Request to upload file
While Controller to loop until postprocessing is finished
JDBC Request - to check your mysql database
When the upload completes, insert a record for the given content with current time. Then Pass this new record's ID to the background job so when processing is finished it can update the same record and insert current time again. Here you go, compare the 2 times...

Resources