Rectangle 27 44

By adding it at the Thread Group level, we ensure that all HTTP requests will share the same cookies.

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

java - Session/cookie management in Apache JMeter - Stack Overflow

java session cookies jmeter session-cookies
Rectangle 27 6

I think that Andrey's answer cannot help. He quotes that each request will use the same cookies BUT according to jmeter manual:

As far as I understand the question, you want each thread to share the same session ID cookie. So it seems to me you need to have two thread groups and execute them consecutively. First thread group (with a single thread that executes once only) should login and save the session cookie value to a global parameter (perhaps you need to use jmeter's scripting capabilities). Then set that cookie in the cookie manager of the second thread group.

java - Session/cookie management in Apache JMeter - Stack Overflow

java session cookies jmeter session-cookies
Rectangle 27 1

Try to increase the ramp up time. I ran into the same issue where the ramp up time was about 1 second then I increased it to 3 seconds per thread and it ran fine.

java - Session/cookie management in Apache JMeter - Stack Overflow

java session cookies jmeter session-cookies
Rectangle 27 0

As you may see (or not) from the image the average time is 712ms when using jmeter with View Results in a Table. Notice that this listener doesn't print out the response body just the request stats.

And here is my code from Java :

public static void main(String[] args) throws Exception{        
        long totalTimeMS = 0;

        for (int i = 0; i < 10; i++) {

        long startTime = System.currentTimeMillis();


        HttpGet get = new HttpGet("http://stackoverflow.com");
        HttpClient client = new DefaultHttpClient();
        client.execute(get);       

        long endTime = System.currentTimeMillis();
        long duration = (endTime-startTime);
        totalTimeMS +=duration;
        System.out.format("Duration %d ms\n", duration);
        }

        System.out.format("Average time is %d ms", (totalTimeMS/10));
    }

So I do not care about the response body as well. But here are the results (lot faster) :

Duration 615 ms
Duration 263 ms
Duration 264 ms
Duration 262 ms
Duration 268 ms
Duration 266 ms
Duration 265 ms
Duration 266 ms
Duration 268 ms
Duration 263 ms
Average time is 300 ms

Now another case in jmeter when using View Results in a Tree when you can actually see the response body plus the View Results in a Table because we still need the time.

I'm not going to attach screenshot because the answer will become less readable but the average time this time is 812 ms so about 100ms more than previously.

Now the java code that cares about the response body (new method) :

public static String convertStreamToString(InputStream is) throws IOException {
        if (is != null) {
            StringBuilder sb = new StringBuilder();
            String line;
            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                while ((line = reader.readLine()) != null) {
                    sb.append(line).append("\n");
                }
            } finally {
                is.close();
            }
            return sb.toString();
        } else {
            return "";
        }
    }

And I've modified slightly the previous code so it prints out the response, simulating the jmeter behavior, posting relevant part :

HttpGet get = new HttpGet("http://stackoverflow.com");
        HttpClient client = new DefaultHttpClient();
        HttpResponse response = client.execute(get);       

        long endTime = System.currentTimeMillis();
        long duration = (endTime-startTime);
        totalTimeMS +=duration;
        System.out.println(convertStreamToString(response.getEntity().getContent()));
        System.out.format("Duration %d ms\n", duration);

Results are following :

Duration 678 ms  + (including printing of response body)
Duration 264 ms + (including printing of response body)
Duration 269 ms + (including printing of response body)
Duration 262 ms + (including printing of response body)
Duration 263 ms + (including printing of response body)
Duration 265 ms + (including printing of response body)
Duration 262 ms + (including printing of response body)
Duration 267 ms + (including printing of response body)
Duration 264 ms + (including printing of response body)
Duration 264 ms + (including printing of response body)
Average time is 305 ms

Reponse time went up by 5 ms. So I don't know how jmeter got to be faster than just plain java code. Anyhow jmeter is really great tool, one of the best one arround (for free).

Thanks for trying it out! If it's not too much trouble, could you try with a web server on your localhost. I think that's where the problem occurs.

With my code, I see no difference with sites hosted abroad. (I tested with s3.amazonaws.com). However, I see the difference with localhost and with servers on the same LAN.

So your conclusion is then it's not tool or code issue? it's a throughput/network/webservice issue?

I think it's a tool or code issue, since JMeter and the Java code have different results on sites that are near. It's important to me since I'm benchmarking sites on the same network. Thanks!

so you get the same results using my code? and which jmeter version? which httpclient version ?

java - Slow Apache httpclient 4.1 compared to JMeter - Stack Overflow

java jmeter apache-httpclient-4.x
Rectangle 27 0

Problem was actually with network, when we tested using different IP address(IP spoofing), all requests were successful. Network was thinking that it was a DoS attack.

Thanks all. I had tried maxThreads & acceptCount and did a lot of tuning in Linux.

So the learning is: Conduct the performance test from a server which is located in the same zone.

java - Apache Tomcat Connection Refused error while load testing with ...

java apache tomcat amazon-web-services jmeter
Rectangle 27 0

Actually I did those test by modifying EJB and WS classes by extends them from "AbstractJavaSamplerClient" and added my codes on "runTest()" method like this : Web Service Sample

public SampleResult runTest(JavaSamplerContext context) {
    SampleResult result = new SampleResult();
    String result1 = "";

    try{

        JMeterVariables vars = JMeterContextService.getContext().getVariables();
        vars.put("EJBRemote", "EJBRemoteVariableContent");
        result.sampleStart();


        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY,
                "weblogic.jndi.WLInitialContextFactory");
        env.put(Context.SECURITY_PRINCIPAL, "weblogic");
        env.put(Context.SECURITY_CREDENTIALS, "weblogic");
        env.put(Context.PROVIDER_URL, "t3://46.34.96.70:1087");
        Context ctx = new InitialContext(env);
        System.out.println("Initial Context created");
        long s = System.currentTimeMillis();

        helloWorld = (HelloWorld) ctx
                .lookup("HelloWorld#server.com.demo.HelloWorld");
        long f = System.currentTimeMillis();
        LogUtil.log("******** EJB REMOTE ********  Start on : "+s+" and end at : "+f+" --> Webservice takes "+(f - s)/1000 + " second",Level.INFO, null);       

        System.out.println("lookup successful");
        System.out.println("Calling EJB method . . .");
        result1=helloWorld.sayHello("10000","50000");
        System.out.println("Output will be in Managed server console");
        System.out.println("********* RESULT from EJB Remote ***********");
        System.out.println(result1);        
        System.out.println("********************************************");


        result.sampleEnd();
        result.setSuccessful(true);
        result.setSampleLabel("SUCCESS: " + result1);

    } catch (Throwable e) {
        result.sampleEnd();
        result.setSampleLabel("FAILED: '" + e.getMessage() + "' || " + e.toString());
        result.setSuccessful(false);
        e.printStackTrace();
        System.out.println("\n\n\n");
        }

    return result;
}

Then You should create jar files from them (Easily I just used export option in MyEclipse) and copy them (with external jar files if need) to JMETER_HOME/lib/ext . Further from JMeter desktop application I added "Java Request" sampler and chose the my desired class from classname option. Now you could add some listener to see the test results . Hope it could be helpful.

java - Web Service and EJB Remote performance benchmark test with Apac...

java web-services jmeter performance-testing
Rectangle 27 0

Got the answer for my question. I have copied the ojdbc14.jar in /lib under the jmeter and restarted the apache it solved my problem.

java - jdbc driver is not loading in apache jmeter using jmeter.proper...

java jdbc jar jmeter
Rectangle 27 0

If you are using JMeter 2.10, it's better to upgrade to 2.11

java - Facing error while configuring for Apache JMeter HTTP(S) Test S...

java apache jmeter
Rectangle 27 0

Please set the following in environment variables:

  • Set JAVA_HOME in Path

java - apache jmeter Test Script Recorder - Stack Overflow

java apache jmeter
Rectangle 27 0

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

java - Web Service and EJB Remote performance benchmark test with Apac...

java web-services jmeter performance-testing
Rectangle 27 0

If I understand correctly, you want to run an entire test plan programmatically from within a Java program. Personally, I find it easier to create a test plan .JMX file and run it in JMeter non-GUI mode :)

Here is a simple Java example based on the controller and sampler used in the original question.

import org.apache.jmeter.control.LoopController;
import org.apache.jmeter.engine.StandardJMeterEngine;
import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.TestPlan;
import org.apache.jmeter.threads.SetupThreadGroup;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.collections.HashTree;

public class JMeterTestFromCode {

    public static void main(String[] args){
        // Engine
        StandardJMeterEngine jm = new StandardJMeterEngine();
        // jmeter.properties
        JMeterUtils.loadJMeterProperties("c:/tmp/jmeter.properties");

        HashTree hashTree = new HashTree();     

        // HTTP Sampler
        HTTPSampler httpSampler = new HTTPSampler();
        httpSampler.setDomain("www.google.com");
        httpSampler.setPort(80);
        httpSampler.setPath("/");
        httpSampler.setMethod("GET");

        // Loop Controller
        TestElement loopCtrl = new LoopController();
        ((LoopController)loopCtrl).setLoops(1);
        ((LoopController)loopCtrl).addTestElement(httpSampler);
        ((LoopController)loopCtrl).setFirst(true);

        // Thread Group
        SetupThreadGroup threadGroup = new SetupThreadGroup();
        threadGroup.setNumThreads(1);
        threadGroup.setRampUp(1);
        threadGroup.setSamplerController((LoopController)loopCtrl);

        // Test plan
        TestPlan testPlan = new TestPlan("MY TEST PLAN");

        hashTree.add("testPlan", testPlan);
        hashTree.add("loopCtrl", loopCtrl);
        hashTree.add("threadGroup", threadGroup);
        hashTree.add("httpSampler", httpSampler);       

        jm.configure(hashTree);

        jm.run();
    }
}

These are the bare mininum JARs required based on JMeter 2.9 and the HTTPSampler used. Other samplers will most likely have different library JAR dependencies.

  • I also hardwired the path to jmeter.properties in c:\tmp on Windows after first copying it from the JMeter installation /bin directory.

Thanks for the answer. This is exactly what I was looking for. Just one more thing. I think adding the LoopController to the ThreadGroup is enough. Adding it separately to the HashTree is not necessary.

Good point on the additions to the HashTree. I was playing around with the JMeter API a little while back but I'm a bit rusty on the details of data structure passed into the JMeter Engine configure method :)

Hi.I am getting the following error. 2014-02-16 18:22:20.957 [jorphan.] (): strPathsOrJars[0] : null/lib/ext DEBUG 2014-02-16 18:22:20.957 [jorphan.] (): Did not find: C:/Users/mvandrangi/workspace/mani/bin DEBUG 2014-02-16 18:22:20.957 [jorphan.] (): Did not find: C:/Users/mvandrangi/Downloads/apache-jmeter-2.11/bin/ApacheJMeter.jar DEBUG 2014-02-16 18:22:20.957 [jorphan.] (): Did not find: C:/Users/mvandrangi/Downloads/apache-jmeter-2.11/bin/ApacheJMeter_core.jar

Interesting. I get the same jorphan DEBUG messages but the program is executing the test plan correctly. I believe that JOrphan is trying to locate those jar files in the JDK/jre/lib/ext directory.

@Peperoncini will the code automatically generate jmx file or should we have to have a jmx file?

api - How to create and run Apache JMeter Test Scripts from a Java pro...

java api automated-tests jmeter
Rectangle 27 0

Try to increase the ramp up time. I ran into the same issue where the ramp up time was about 1 second then I increased it to 3 seconds per thread and it ran fine.

java - Session/cookie management in Apache JMeter - Stack Overflow

java session cookies jmeter session-cookies
Rectangle 27 0

jmeter.properties
CookieManager.save.cookies=true
CookieManager.name.prefix=mycookie_

Next, add a HTTP cookie manager in the same thread group as your java sampler.

Then in your java sampler add:

JMeterVariables jmv = JMeterContextService.getContext().getVariables();
Iterator<Map.Entry<String,Object>> it = jmv.getIterator();
while(it.hasNext()){
    Map.Entry<String,Object> v = it.next();
    System.out.println("name: " + v.getKey() + " value: " + v.getValue());
}

java - Session/cookie management in Apache JMeter - Stack Overflow

java session cookies jmeter session-cookies
Rectangle 27 0

jmeter.properties
CookieManager.save.cookies=true
CookieManager.name.prefix=mycookie_

Next, add a HTTP cookie manager in the same thread group as your java sampler.

Then in your java sampler add:

JMeterVariables jmv = JMeterContextService.getContext().getVariables();
Iterator<Map.Entry<String,Object>> it = jmv.getIterator();
while(it.hasNext()){
    Map.Entry<String,Object> v = it.next();
    System.out.println("name: " + v.getKey() + " value: " + v.getValue());
}

java - Session/cookie management in Apache JMeter - Stack Overflow

java session cookies jmeter session-cookies
Rectangle 27 0

I have no experience with Apache JMeter, but generally if you want to use your Java program to kick off something else, you use the Process class via the Runtime class. The code for this is -

Runtime runtime = Runtime.getRuntime();
Process p = runtime.exec("the script");//Thats it! You have now started your script!

Note that you wont see the process spitting output to the console. You can programmatically capture the input and output streams using the Process class:

InputStream input = p.getInputStream();
OutputStream output = p.getOutputStream();

And that will allow you to analyze the input/output during the run of your java program.

for what im researching now on jmeter they downvoted you because is has an api for java, and that what the guy asked

api - How to create and run Apache JMeter Test Scripts from a Java pro...

java api automated-tests jmeter
Rectangle 27 0

Looks like your client ran out of ephemeral port or there's some problem with your client environment. Are you using Windows?

You can possibly do at least the following:

  • Windows: look into this article for solution for Windows system as host for jmeter.
  • Use Linux system instead as host to run you Jmeter load-scenarios.

As well you possibly will find this article useful for your testing activities (I've seen Jboss in tags).

When an HTTP request is made, an ephemeral port is allocated for the TCP / IP connection. The ephemeral port range is 32678 61000. After the client closes the connection, the connection is placed in the TIME-WAIT state for 60 seconds.

If JMeter (HttpClient) is sending thousands of HTTP requests per second and creating new TCP / IP connections, the system will run out of available ephemeral ports for allocation.

. . .

Otherwise, the following messages may appear in the JMeter JTL files:

The solution is to enable fast recycling TIME_WAIT sockets.

Other options include TCP_FIN_TIMEOUT to reduce how long a connection is placed in the TIME_WAIT state and TCP_TW_REUSE to allow the system to reuse connections placed in the TIME_WAIT state.

This allows reusing sockets in TIME_WAIT state for new connections - a safer alternative to tcp_tw_recycle

/sbin/sysctl -w net.ipv4.tcp_tw_reuse=1

The tcp_tw_reuse setting is particularly useful in environments where numerous short connections are open and left in TIME_WAIT state, such as web-servers. Reusing the sockets can be very effective in reducing server load.

Maximum number of timewait sockets held by system simultaneously

/sbin/sysctl -w net.ipv4.tcp_max_tw_buckets=30000

or the same but in another way - add the lines below to the /etc/sysctl.conf file so that the change survives reboot:

net.ipv4.tcp_max_tw_buckets = 30000
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1

As well on the server's side look onto result of ulimit -n. Default value is 1024 for the limit of max open files, which can explain appearance of BindExceptions at 1000 connections.

As well you can monitor number of connections between the server and jmeter during test-run using e.g.

netstat -an | grep SERVER_PORT | wc -l

to define limit of connections - if any.

So, any new details? If Windows OS: same behavior after applying all the instructions?

I am using CentOS 5 for Apache Server and testing from Windows XP client PC. I have followed the detail procedure of the referenced link. However, it didn't work. But I found something that if I changed KeepAliveTimeout into 15 in httpd.conf file in CentOS server, it does solved the problem. Honestly, I don't clearly understand why it is solved by doing it. Do you have any idea about it?

Have you increased or decreased KeepAliveTimeout value? Please look into update in answer, I've added several common issues for load-testing using linux boxes. Maybe something of these point will be helpful for you.

java - Apache multiple requests with jmeter - Stack Overflow

java apache jmeter jboss5.x
Rectangle 27 0

Try adjusting the maxThreads and acceptCount attributes of the http connector in server.xml:

Each incoming request requires a thread for the duration of that request. If more simultaneous requests are received than can be handled by the currently available request processing threads, additional threads will be created up to the configured maximum (the value of the maxThreads attribute). If still more simultaneous requests are received, they are stacked up inside the server socket created by the Connector, up to the configured maximum (the value of the acceptCount attribute). Any further simultaneous requests will receive "connection refused" errors, until resources are available to process them.

I faced similar problem with tomcat and it was solved by using maxConnections settings along with acceptCount in server.xml. I set both to a high value, say 5000, and I don't get connection exception when hitting tomcat with 1000+ users.

java - Apache Tomcat Connection Refused error while load testing with ...

java apache tomcat amazon-web-services jmeter
Rectangle 27 0

  • Try using full path instead of relative. If it solves your issue - check the relative path.
  • Make sure that user.classpath property isn't getting overriden via user.properties file or command-line arguments
  • As the last resort you can drop Oracle JDBC driver to /lib folder of your JMeter installation
  • You can add additional files and folders to classpath at Test Plan level.

Also I believe you need to use more "fresh" client JDBC library for Oracle 11, I would recommend downloading ojdbc6.jar which is designed to work with Java 6 instead of ojdbc4.jar which is for Java 1.4.

java - jdbc driver is not loading in apache jmeter using jmeter.proper...

java jdbc jar jmeter
Rectangle 27 0

I also faced same problem.So,i upgrade java 1.6 to 1.7 then the problem is resolved

set the java path in jmeter.bat file like

java - Facing error while configuring for Apache JMeter HTTP(S) Test S...

java apache jmeter
Rectangle 27 0

The 400 Bad Request error is an HTTP status code that probably you sent a malformed request to the server and the server was unable to understand or process the request.

I recorded the url through jmeter proxy and than running the test. I did not changed anything not even cookie or header . After recording i am running test directly.Do i need to change some data? or i need to set cookie? ot sth else. Myapp requires login without that youcan not access any other pages.

From my experience the JMeter proxy isn't very reliable (haven't used it in ages so may have improved). I would, instead use a different http sniffing tool (eg. Fiddler) and then build my requests for JMeter manually. Chances are the Proxy missed something.

I am not able to fix out yet. can you please provide any good tutorial link

java - Apache Jmeter giving 404 error - Stack Overflow

java jmeter