什么 bug,你不说大家咋知道呢

解决方案 »

  1.   

    补充:bug描述,当程序运行一段时间之后,新的请求不会再被激活,一直是一个被压住的状态(suspend)-->对于一个存在的broadcaster(房间),当新建一个broadcaster(新的房间),运行正常。且后台不会报错。
      

  2.   

    @RequestMapping(value = "/comet", method = RequestMethod.GET)
    public ModelAndView subscribe(HttpServletRequest request,
    HttpServletResponse response) throws Exception {
    AtmosphereResource resource = (AtmosphereResource) request
    .getAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE);
    this.doGet(resource, request, resource.getResponse());
    ModelAndView mv = new ModelAndView(new NoOpView());
    return mv;
    } @RequestMapping(value = "/comet", method = RequestMethod.POST)
    public ModelAndView broadcastMessage(HttpServletRequest request,
    HttpServletResponse response) throws Exception {
    this.doPost(request, response);
    ModelAndView mv = new ModelAndView(new NoOpView());
    return mv;
    } protected void doGet(AtmosphereResource resource,
    HttpServletRequest request, AtmosphereResponse response) {
    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0); String path = request.getParameter("path");
    if (path == null || path.isEmpty() == true) {
    sendError(resource, "");
    return;
    }
    int userId = 0;
    try 
    {
    //从当前请求中获取,用户ID


    catch (Exception e)
    {
    e.printStackTrace();
    DebugUtil.log("Comet userId error: ");
    DebugUtil.log(e.toString() + "\n" + DebugUtil.getStack(e));
    }
    if (userId == 0) 
    {
    sendError(resource, "");
    return;
    }
    Integer number=addUserToroomsource(resource.uuid(),userId, path);

    Broadcaster broadcaster = BroadcasterFactory.getDefault().lookup("/" + path, true);
    resource.setBroadcaster(broadcaster);
    resource.addEventListener(new myAtmosphereResourceEventListener());
    resource.suspend();
    } private Integer addUserToroomsource(String uuid, int userId, String path) {

    return null;
    } private void sendError(AtmosphereResource resource, String errorMessage) {
    sendError(resource, errorMessage, "");
    } public static void sendError(AtmosphereResource resource,
    String errorMessage, String errorInfo) {
    StringBuilder json = new StringBuilder("{\"result\": \"");
    json.append(errorMessage);
    json.append("\"");
    if (errorInfo != null) {
    json.append(", \"message\": \"");
    json.append(errorInfo);
    json.append("\"");
    }
    json.append("}");
    Broadcaster b = BroadcasterFactory.getDefault().lookup("/error", true);
    b.addAtmosphereResource(resource);
    b.broadcast(json.toString()); } protected void doPost(HttpServletRequest request,
    HttpServletResponse response) {
    JSONObject jsonObject = null;
    String path = null;
    String message = null;
    try {
    String str = request.getReader().readLine();
    if (str != null) {
    jsonObject = new JSONObject(str);
    }
    } catch (Exception e) {
    }
    if (!jsonObject.isNull("path")) {
    path = jsonObject.getString("path");
    }
    if (!jsonObject.isNull("message")) {
    message = jsonObject.getString("message");
    }
    AtmosphereResource resource=(AtmosphereResource)
    request.getAttribute(ApplicationConfig.SUSPENDED_ATMOSPHERE_RESOURCE_UUID);
    Broadcaster broadcaster = BroadcasterFactory.getDefault().lookup("/" + path);
    if (broadcaster != null) {
    broadcaster.broadcast(message);
    }
    }
      

  3.   

    特定的框架?什么意思?就是atmosphere 框架啊。
      

  4.   

    检查一下是不是在等待 peer 回写
      

  5.   


    光看get/post,没啥问题。
      

  6.   


    光看get/post,没啥问题。整个程序就是这2个方法,get(请求被压住),post(接受数据,激活被压住的连接--广播)
      

  7.   


    部署到服务器才会出现BUG,在本地测试,或者访问量很小的情况不会出现。就不知道如何在本地进行模拟访问???
      

  8.   

    用 LoadRunner 或者 JMeter 试试。
    也可以参考下:
    sql 性能模拟用户测试
      

  9.   


    都用过了,没有用,LoadRunner 11 录制脚本,运行的时候会报错,一直会说资源找不到。
                       JMeter  只能模拟http请求,不能加载js,因为请求都是js去做的事情
      

  10.   

    那你自己写脚本模拟用户测吧:
    sql 性能模拟用户测试
      

  11.   


    这点访问量 恐怕不够,我还是想想自己写脚本,谢谢你的提议。我也与框架作者交流过,一直没找出问题的原因所在,很是困惑。这不一定是框架的问题,现在的问题是你根本就不知道是哪里的问题。我也一直在查找自身代码的原因,只能有一套完整的测试方法了,我才能去判断到底问题在哪里,请问你对tomcat的集群了解如何?
      

  12.   


    现在考虑做,tomcat集群。但是主站项目的原因,不能与apache集成。现在的设想是N个tomcat集群,如何保证能共享广播数据? RedisBroadcaster 这个atmosphere 插件用过没?这个就是做集群的广播类,我现在配置上去有点问题,启动项目会报错: java.net.ConnectException: Connection refused: connect