all sessions sending the same content to the application testing

Hi Gatling Experts,

I want to make a simulation where my program read a file on disk and put its content into a variable in order that every vusers (gatling sessions) use the same content of the file for

every request sending to the application during the bench operation (and especially, I want the reading operation on disk performs only once ).

Therefore, can you see if what I have done is correct in the excerpt of my simulation program ?

If not, Have you any idea to correct it ?

Here is an excerpt of my simulation program:

class TestSimulation extends Simulation {

val httpProtocol = http .baseURL(“https://testsite”) —so on …)

val headers_0 = Map(""“Accept”"" → “”“text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8"”")

// read the content of a file on disk and store it in a variable

var xmlbodyLine = “”
val stream = scala.io.Source.fromFile(“D:\data\mytestxmlfile.xml”)
for (line ← stream.getLines().mkString("\n"))
xmlbodyLine = xmlbodyLine + line
stream.close()
printf("%s\n",xmlbodyLine)

val scn = scenario(“Call my WebService”)
.during(5 minutes){
exec(
http(“Call WebService”)
.post("""/""")
.headers(headers_1)
.body(StringBody(xmlbodyLine))
.check(status.is(200))
)
}

and so on …

setUp(scn.inject(…)

}

Thanks a lot

Viet Minh

Hi Viet Minh,

Globally, this is fine.
However, there are some little things to do to make it clearer, less error-prone and to be sure that it would run fine:

  • Since xmlBodyLine won’t be modified afterwards, make it a val, not a var. Plus, it protects you from modifying it by mistake.
  • Here, you don’t need a for-comprehension, since mkString already gives a String, there’s nothing to iterate over.
  • Do not depend on a absolute path. It would run fine on your computer, but has all the chances to fail on someone else’s computer. Put the file in the classpath (lib folder in the bundle, src/test/resources with the Maven archetype/plugin or the SBT plugin) and use ClassLoader.getResourceAsStream(…)

My cleaned up version :

val xmlBodyLine = { val resource = getClass.getClassLoader.getResourceAsStream("mytestxmlfile.xml") val source = scala.io.Source.fromInputStream(resource) val content = source.mkString("\n") source.close() resource.close() content }

Hope this helps !

Cheers,

Pierre

Hi Pierre

Thank for your help

But

I am new to Highcharts, So I want to ask you some more questions about it.

In the gatling configuration file, we have these lines below which indicate us the way the results of testing operation will be represented.

charting {
#noReports = false
#maxPlotPerSeries = 1000
#accuracy = 10 # in ms
indicators {

So I have the following questions.

  1. the maxPlotPerSeries means the max number of dots for a line graph , isn’t it ?

if I want to have more plots in the graphs, for example, I must do as below ?

charting {
#noReports = false
#maxPlotPerSeries = 1000
maxPlotPerSeries = 2000
#accuracy = 10 # in ms
indicators {

  1. What is the meaning of accuracy ? is it the rendering interval (used for calculating the plots) for the representation in the line graph ?

Thanks

Viet Minh

No worries, always open to good questions :slight_smile:

  1. It is exactly that. However, please note that setting maxPlotPerSeries to a higher value means more work for Highcharts, and will require more CPU to compute the charts. 2000 seems pretty reasonable though.

  2. Exactly. This setting controls the minimum accuracy of the the various graphs and stats in the Gatling reports.
    Note that a setting it to a lower value (meaning a greater accuracy) will increase the memory usage when generating reports.

Hi Pierre

Thank for your help

But

I am new to Highcharts, So I want to ask you some more questions about it.

In the gatling configuration file, we have these lines below which indicate us the way the results of testing operation will be represented.

charting {
#noReports = false
#maxPlotPerSeries = 1000
#accuracy = 10 # in ms
indicators {

So I have the following questions.

  1. the maxPlotPerSeries means the max number of dots for a line graph , isn’t it ?

Absolutely,