[jboss-user] [jBPM] - Re: Strange behavior and Performance

Andre Luiz Silva do-not-reply at jboss.com
Mon Apr 16 12:32:57 EDT 2012


Andre Luiz Silva [https://community.jboss.org/people/andrens] created the discussion

"Re: Strange behavior and Performance"

To view the discussion, visit: https://community.jboss.org/message/730344#730344

--------------------------------------------------------------
We started several threads calling the webservice to start the process. Here's the code:

package timeconsuming;


import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;


import javax.ws.rs.core.MultivaluedMap;


import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.client.apache.ApacheHttpClient;
import com.sun.jersey.client.apache.config.DefaultApacheHttpClientConfig;
import com.sun.jersey.core.util.MultivaluedMapImpl;


public class JbpmProcessTest {

          private static final int MAX_TIME = 3; //test maximum time in hours
          private static final int THREADS = 50;  //test threads count
          private static final String USER = "krisv";
          private static final String PASSWORD = "krisv";
          private static final String PROCESS_URL = "http://CPQD037542:8080/gwt-console-server/rs/process/definition/%s/new_instance";


          public static void main(String[] args) {
                    try {
                              new JbpmProcessTest().instantiateProcess(1000, "Looping", true, "TesteScript");
                    } catch (Exception ex) {
                              ex.printStackTrace();
                    }
          }


          public void instantiateProcess(int amount, String title, boolean isThread, final String processId) throws IOException {
                    ExecutorService executor = null;

                    if (isThread) {
                              executor = Executors.newFixedThreadPool(THREADS);
                    } else {
                              executor = Executors.newSingleThreadExecutor();
                    }


                    File file = new File("C:\\JBPM" + title + "Test-" + THREADS + ".txt");


                    if (!file.exists() && !file.createNewFile()) {
                              System.out.println("Error to create file!");
                              return;
                    }


                    final FileWriter writer = new FileWriter(file);
                    writer.write("JBPM" + title + "Test\n");


                    final List<Long> requestDelays = new ArrayList<Long>();


                    Date initialDate = new Date();
                    System.out.println("Initiated: " + initialDate);
                    writer.write("Initiated: " + initialDate + "\n");


                    for (int i = 0; i < amount; i++) {
                              final int idx = i;
                              executor.execute(
                                        new Runnable () {
                                                  public void run() {
                                                            DefaultApacheHttpClientConfig apcc = new DefaultApacheHttpClientConfig();
                                                            apcc.getProperties().put(DefaultApacheHttpClientConfig.PROPERTY_HANDLE_COOKIES, true);
                                                            apcc.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
                                                      ApacheHttpClient client = ApacheHttpClient.create(apcc);


                                                            WebResource webResource = client.resource(String.format(PROCESS_URL, processId));

                                                            // Just to authenticate
                                                            try {
                                                                      webResource.post(ClientResponse.class);
                                                                      MultivaluedMap<String, String> formData = new MultivaluedMapImpl();
                                                                      formData.add("j_username", USER);
                                                                      formData.add("j_password", PASSWORD);
                                                                      webResource.path("/j_security_check").type("application/x-www-form-urlencoded").post(String.class, formData);
                                                            } catch (UniformInterfaceException ex) {
                                                                      // DO NOTHING
                                                            }

                                                            long initialDelay = new Date().getTime();
                                                            ClientResponse response = webResource.post(ClientResponse.class);


                                                            long endDelay = new Date().getTime() - initialDelay;
                                                            System.out.println("response " + idx + " : " + response.getStatus() + " Delayed: " + endDelay / 1000);


                                                            try {
                                                                      writer.write("response " + idx + " : " + response.getStatus() + " Delayed: " + endDelay / 1000 + "\n");
                                                                      writer.flush();
                                                                      requestDelays.add(endDelay);
                                                            } catch (IOException ex) {
                                                                      // ex.printStackTrace();
                                                            }
                                                            client.destroy();
                                                  }
                                        }
                              );
                    }


                    try {
                              executor.shutdown();
                              executor.awaitTermination(MAX_TIME, TimeUnit.HOURS);
                    } catch (InterruptedException ex) {
                              ex.printStackTrace();
                    }


                    Date endDate = new Date();
                    Long delay = endDate.getTime() - initialDate.getTime();
                    System.out.println("Finalized: " + endDate);
                    writer.write("Finalized: " + endDate + "\n");
                    System.out.println("Total Execution Time: " + delay / 1000);
                    writer.write("Total Execution Time: " + delay / 1000 + "\n");


                    Long totalDelay = 0L;
                    for (Long requestDelay : requestDelays) {
                              totalDelay += requestDelay;
                    }


                    System.out.println("Request Delay Average: " + (totalDelay / 1000) / requestDelays.size());
                    writer.write("Request Delay Average: " + (totalDelay / 1000)
                                        / requestDelays.size() + "\n");
                    writer.write("Total Request Amount: " + amount + "\n");
                    writer.close();
          }
}
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/730344#730344]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120416/706b6f8c/attachment-0001.html 


More information about the jboss-user mailing list