how to add dynamic values to each post request of each user from feeder

3,500 views
Skip to first unread message

krishnaprasa...@gmail.com

unread,
Apr 14, 2016, 12:54:06 AM4/14/16
to Gatling User Group
Hi ,

I am trying to simulate the load for rest API  Post request  call   to OPETSDB  to add time series test data in millions as part of quick POC. I found  Gatling might be right tool for this job  since it is based on scala and Akka framework , can spawn requests very quickly and trying with this tool.

I have written  example program  where  body ()  should be  populated with dynamic values from feeder  .  



  val scn = scenario("Simulation for the opentsdb datapoints post service").feed(myCustomFeeder).repeat(repeatCount) {

    exec(
      http(session => "Post a DataPoint")
        .post(customerLink)
        .body( StringBody("""{
                 "metric": "${metric}",
                  "timestamp": "${timestamp}",
                  "value": "${value}" ,
                  "tags": { 
                      "host": "${host}",
                       "if": "${if}"
                      }
                     }"""))
        .check(status is 200)
    )  }

-----------------------------------------------------------------------------------
  import io.gatling.core.feeder._
 
  val myCustomFeeder = new Feeder[String] {
  import scala.util.Random
  override def hasNext = true
  override def next: Map[String, String] = {
    val index = Random.nextInt(4)
    val preDeftagVals = preDefTagValset(index%2)
    val timeDelta = Random.nextInt(120* 60* 1000)
    Map("metric" -> preDefinedMetrics(index), "timestamp" -> s"${Calendar.getInstance().getTimeInMillis()-timeDelta}" , "value"-> s"${prefDefinedValues(index)}" , prefDefTagKeys(0) -> preDeftagVals(0), prefDefTagKeys(1) -> preDeftagVals(1))
    }
 }
 

-------------------------------------------------------

Note :  preDefinedMetrics() method in this example is just few records for testing. All values will be generated be dynamically  for each request  like "timestamp"  value for each one second.


Issue :  Post request with dynamic values for each repeat request of each user to rest api call.

This above  code with feeder  is injecting one record  into session for each user based on number of  threads configured. Means if I have 10 users each user session  record values are different.  But the issue is if I repeat the request for  10 times with repeat count for the scenario  for user  all 10 post requests have same   data  in post request parameters.

I can't  expect 1 million users  for  one million records  to call rest api with different  dynamic parameter values .

Please suggest or point me to  example   how can I make sure all my post request parameter values will be dynamically set  while post request is firing Rest API call.

I am pretty now to this Gatling tool , but I considered this for evaluation due to it's scala , akka framework.  I am sure there will some kind of solution since this is pretty basic scenario.

Also  populating data to CSV file ( ten million records )  and using csv feeder for  making those records available in  session does not look   right for me.  So there should a way to  feed data dynamically in each post request  right.  I tired to  define  a method  for  data generation and call that from body() , but it is injecting only one record  for all requests.

Thanks
Krishna Prasad

krishnaprasa...@gmail.com

unread,
Apr 14, 2016, 2:33:00 AM4/14/16
to Gatling User Group
I think I found  some solution for this

I need to do exec().exec() chaining

in the first exec()  I am able to set  latest values to session and followed by next  exec()  method which does http post  to rest call. This way I can have different values in each request.

Still exploring on this for  better solution for further process to  simulate  1000  threads with  many repeats to simulate  10 million records across different time stamps one per millisecond.



Thanks
-Krishna Prasad

Nandam Mahesh

unread,
Jul 25, 2017, 2:11:32 AM7/25/17
to Gatling User Group
Hi Krishna Prasad,


I am also facing the same issue currently. I need to generate and pass a new Dynamic 20digit numeric ID to the Exec method each time. (If the repeat is 100 then 100 time i need to generate and pass it to the exec method to run) But only the 1st time random value is passing into the method :(:(   .

Can you please let me know how it can be resolved. 

Many thanks in advance.


feed(feeder)
      .exec(http("Create WaitList")
      .put("gateway/1.0/waitlist")
      .body(StringBody(
        """{
             "Customer": {
                "Name": "John, Kennedy",
                "PrimaryNumber": "8528528528",
                "AccountNumber": "0952911090201"
              },
              "WorkOrder": {
                "Id": """"+ dataDev.getWorkOrderId() +s"""",
                "JobUnits": "16",
                "ManagementArea": "4C",
                "BusinessUnit": "821010000220",
                "JobTypeCd": "TC",
               "JobNum": "559168",
                "TimeSlot": {
                    "TimeSlotCd":"6",
                    "StartTime":"04:00:00",
                    "EndTime":"06:00:00",
                     "AppointmentDate":"2017-07-23"
                }
              },
                "FirstAvailableTimeSlot": {
              "TimeSlotCd":"6",
                  "StartTime":"06:00:00",
                  "EndTime":"08:00:00",
                  "AppointmentDate":"2017-07-24"
                },
              "PreferredTimeSlot": [{
                "TimeSlotCd": "6",
                "StartTime":"06:00:00",
                "EndTime": "08:00:00",
                "AppointmentDate": "2017-07-25"
              }],
              "OrderEntryPlatform": "WFA"
            }""")).asJSON
      .check(status is 200)
      .check(jsonPath("$.WLRequestId").saveAs("wlreqId"))
      .check(jsonPath("$.WLRequestStatus").saveAs("wlstatus"))
    )


Mahesh Nandam
9884494730.
Reply all
Reply to author
Forward
0 new messages