2 Replies Latest reply on Apr 16, 2012 12:32 PM by Andre Luiz Silva

    Strange behavior and Performance

    Andre Luiz Silva Newbie

      I'm trying to do some testing with JBPM and I'm having a strange behavior. With several simultaneous calls to JBPM seems to treat them in sequence, not in parallel.


      Each request takes twice as long as the previous one. Anyone ever had this problem? know how to solve or improve performance?

        • 1. Re: Strange behavior and Performance
          Esteban Aliverti Master

          Could you please share with us how are you doing your tests and what are you doing inside the process you are using?

          • 2. Re: Strange behavior and Performance
            Andre Luiz Silva Newbie

            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();

                      }

            }