开发者

Creating multiples instances in Google App Engine JAVA

开发者 https://www.devze.com 2023-04-02 19:49 出处:网络
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 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 jav开发者_运维技巧a.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

Creating multiples instances in Google App Engine JAVA

without luck.

Creating multiples instances in Google App Engine JAVA

So, what can I do?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消