Creating multiples instances in Google App Engine JAVA

爱⌒轻易说出口 提交于 2019-12-08 07:45:15

问题


I am testing Google App Engine using JAVA and I want to test to run multiples instances in parallel. However, I don't know how to activate multiples instances.

I tried running this Servlet in different browser (also I tried running concurrent calls in a different machine - with different IP)

import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
import java.math.*;
public class SimpleServlet extends HttpServlet
{
  //A variable that is NOT thread-safe!

  public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException
  {
    doPost(req, resp);
  }
  public void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException
  {
     int counter = 0;
    resp.getWriter().println("<HTML><BODY>");
    resp.getWriter().println(this + ": <br>");
    for (int c = 0; c < 10; c++)
    {
      resp.getWriter().println("Counter = " + counter + "<BR>");
      try
      {
        //Thread.currentThread().sleep( 500);
          for (int e=0;e<9999;e++) {
          }
        Thread.sleep(500);

        counter++;
      }
      catch (InterruptedException exc) {
        resp.getWriter().println("I can't sleep<BR>");
      }
    }
    resp.getWriter().println("</BODY></HTML>");
  }
}

Every Servlet took 5 seconds to process but the requests are pooled in a single instance, for example if I run 10 times this servlet then it took 50 seconds to process the last one.

I tried using:

<threadsafe>true</threadsafe>

but it do nothing.

I tried changing the settings

without luck.

So, what can I do?


回答1:


By setting <threadsafe>true</threadsafe>, enables your application to handle concurrent requests inside the same instance. So, if you need to test how your application behaves with multiple instances active, you better disable this option.

Also, you can create traffic generator to make lots of requests to your app and thus cause the "wake up" of more that one instances.



来源:https://stackoverflow.com/questions/7292376/creating-multiples-instances-in-google-app-engine-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!