1

I'm executing JMeter task for a few hours on a server,

I want to be able to pause execution for a few seconds/minutes and resume when server finish restarted

Is there a way to signal JMeter to pause and resume its execution?

I saw similar question, but it doesn't fit my issue

Ori Marko
  • 56,308
  • 23
  • 131
  • 233

1 Answers1

1

As of current JMeter version 5.3 there is no way to accomplish your "issue" with built-in JMeter components.

The easiest solution I can think if is: given you're restarting your server it should be not available for some time and when it becomes available - it should respond with a HTML page containing some text.

So you can "wait" for the server to be up and running as follows:

  1. Add JSR223 Sampler to the appropriate place in the Test Plan where you need to "wait' for the server to be up and running
  2. Put the following code into "Script" area:

    import org.apache.http.client.config.RequestConfig
    import org.apache.http.client.methods.HttpGet
    import org.apache.http.impl.client.HttpClientBuilder
    import org.apache.http.util.EntityUtils
    
    SampleResult.setIgnore()
    
    def retry = true
    
    def requestConfig = RequestConfig.custom().setConnectTimeout(1000).setSocketTimeout(1000).build()
    def httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build()
    while (retry) {
        def httpGet = new HttpGet('http://jmeter.apache.org')
        try {
            def entity = httpClient.execute(httpGet).getEntity()
            if (EntityUtils.toString(entity).contains('Apache JMeter')) {
                  log.info('Application is up, proceeding')
                retry = false
            } else {
                  log.info('Application is still down, waiting for 5 seconds before retry')
                sleep(5000)
            }
        }
        catch (Throwable ex) {
            sleep(5000)
            ex.printStackTrace()
        }
    }
    
  3. That's it, the code will try to open the web page and look for some text in it, if the page doesn't open and/or text is not present - it will wait for 5 seconds and retry

More information:

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thank you, but I don't want to send additional request before every request to server. I already know when to pause and I want to send pause/resume to JMeter execution – Ori Marko May 25 '20 at 15:22
  • If you need to pause JMeter for some time (i.e. "sleep") just use [Flow Control Action](https://jmeter.apache.org/usermanual/component_reference.html#Flow_Control_Action) sampler and [Synchronizing Timer](https://www.blazemeter.com/blog/using-jmeter-synchronizing-timer/) combination – Dmitri T May 25 '20 at 15:34
  • But how can I call it by demand ? E.g. after 1 hour before server about to restart (time is unknown before execution) – Ori Marko May 25 '20 at 15:40
  • If your question is about suspending/resuming any application, not specifically JMeter, in Linux you can use `kill -STOP ${JMETER_PID}` for suspend the process and `kill -CONT ${JMETER_PID}` for resume. In Windows you can do something like `Invoke-WindowsApi "kernel32" ([bool]) "DebugActiveProcess" @([int]) @(JMETER_PID)`. – Dmitri T May 25 '20 at 15:55