You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jersey多层子资源调用耗时过长问题排查求助

Jersey子资源链调用异常耗时:从EventResource到AttendeeSessionResource耗时超2分钟

我最近碰到一个非常诡异的性能问题:在我的Jersey REST服务中,从EventResource#getAttendeeSession()到AttendeeSessionResource#getAttendeeSessions()的调用过程居然耗时整整2分钟左右!

我通过调试追踪到,所有的时间都消耗在Jersey框架代码的Stages.class中lastStage.apply(continuation.result())这一行,完全没有涉及到我自己的业务逻辑。

我做了一些排查尝试:

  • 一开始怀疑是不是因为这是子资源的子资源(嵌套子资源)导致的,但直觉上觉得这个逻辑不成立
  • 我试过手动调用locator.inject(resource)和不调用的情况,两种场景下耗时几乎完全一致,平均都是110秒左右

下面是我的资源类代码:

根资源类

@Path("client")
public class WebinarResource extends AbstractResource {
    @Path("{clientId}/event/{eventId}")
    public EventResource getEvent(@ApiParam(value = "", required = true) @PathParam("clientId") long clientId, @ApiParam(value = "", required = true) @PathParam("eventId") long eventId) throws SQLException {
        EventResource resource = new EventResource(clientId, eventId);
        locator.inject(resource);
        return resource;
    }
}

子资源类

public class EventResource extends AbstractResource{
    @Path("/attendeesession")
    public AttendeeSessionResource getAttendeeSession(){
        System.out.println("EventResoure#getAttendeeSession() called: " + LocalDateTime.now());
        System.out.println("curr time milis: "+System.currentTimeMillis());
        AttendeeSessionResource resource = new AttendeeSessionResource();
        locator.inject(resource);
        return resource;
    }
}

子子资源类

@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public class AttendeeSessionResource extends AbstractResource{
    @PathParam("eventId")
    private long eventId;
    //...
    @GET
    @WebinarSecurityFilter
    @WebinarThrottlingFilter(apiPrefix = "GET_EVENT_ATTENDEE_VIEWING_SESSIONS_", maxCallsPerMinute = MAX_CALLS_PER_MINUTE, endpointName = "Event-level Attendee Viewing Sessions")
    @WebinarClientValidationFilter
    @WebinarEventValidationFilter
    public Response getAttendeeSessions(@QueryParam("sessiontype") String sessionType, @QueryParam("pageoffset") Integer pageOffset){
        System.out.println("AttendeeSessionResource#getAttendeeSessions() called: " + LocalDateTime.now());
        System.out.println("curr time milis: "+System.currentTimeMillis());
        // 这里已经是资源方法的起始位置,但耗时已经达到110秒了?这到底是为什么?
    }
}

想请教一下各位:这种场景下可能存在什么问题?为什么还没进入业务方法就消耗了这么久的时间?

内容的提问来源于stack exchange,提问作者Esteban Rincon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:30:11