在Google App Engine JAVA中创建多个实例 [英] Creating multiples instances in Google App Engine JAVA

查看:217
本文介绍了在Google App Engine JAVA中创建多个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JAVA测试Google App Engine,我想测试并行运行多个实例。但是,我不知道如何激活多个实例。

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.

我尝试在不同的浏览器中运行此Servlet(我也尝试在不同的机器上运行并发调用 - 具有不同的IP)

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>");
  }
}

每个Servlet需要5秒钟才能处理,但请求是汇总在一个实例中,例如,如果我运行10次这个servlet,那么花费50秒来处理最后一个。

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.

我尝试使用:

<threadsafe>true</threadsafe>

但它什么都不做。

I尝试更改设置

没有运气。

那么,我该怎么办?

推荐答案

通过设置< threadsafe> true< / threadsafe> ,使您的应用程序能够处理同一实例中的并发请求。因此,如果您需要测试应用程序在多个实例处于活动状态时的行为,最好禁用此选项。

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.

这篇关于在Google App Engine JAVA中创建多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆