简体   繁体   English

在Google App Engine JAVA中创建多个实例

[英]Creating multiples instances in Google App Engine JAVA

I am testing Google App Engine using JAVA and I want to test to run multiples instances in parallel. 我正在使用JAVA测试Google App Engine,并且想测试要并行运行多个实例。 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) 我尝试在不同的浏览器中运行此Servlet(也尝试在不同的计算机上使用不同的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. 每个Servlet需要5秒钟来处理,但是请求被合并到一个实例中,例如,如果我运行10次此Servlet,则需要50秒钟来处理最后一个。

I tried using: 我尝试使用:

<threadsafe>true</threadsafe>

but it do nothing. 但它什么也没做。

I tried changing the settings 我尝试更改设置

设定

without luck. 没有运气。

在此处输入图片说明

So, what can I do? 那么,我该怎么办?

By setting <threadsafe>true</threadsafe> , enables your application to handle concurrent requests inside the same instance. 通过设置<threadsafe>true</threadsafe> ,可以使您的应用程序处理同一实例内的并发请求。 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. 另外,您可以创建流量生成器以向您的应用发出大量请求,从而导致多个实例的“唤醒”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM