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

Node.js服务器每秒仅处理200请求性能问题问询

性能瓶颈排查请求

我对一个简单的GET路由做了JMeter负载测试,测试配置见截图。这个路由的逻辑很简单:通过TypeORM在PostgreSQL数据库执行select-where语句查询单个实体,然后返回响应。

核心代码

路由处理函数

async function checkIfCodeExist(req: Request, res: Response): Promise<void> {
    const codeOnline = req.params.codeOnline as string;

    const session = await sessionInformationRepository.findOneBy({
        codeOnline,
    });

    if (null === session) {
        res.sendStatus(404);
        return;
    }

    res.sendStatus(204); 
} 

Repository层代码

const findOneBy = async (
    args: FindSessionByParams
): Promise<SessionInformation | null> => {
    const session = await SessionEntity.findOneBy({
        ...omitBy(args, (v) => null == v),
    });

    if (!session) {
        return null;
    }
    return convertToSessionInformation(session as SessionEntity);
};

实体转换代码

// 转换器之间没有无限递归循环
// ORM实际只加载1级依赖,避免"循环引用"问题
// 示例:加载的session有"participants"映射属性,但这些participants实体不会加载"session"属性
export const convertToSessionInformation = (
    entity: SessionEntity
): SessionInformation => {
    return omitBy(
        {
            ...entity,
            startAt: entity.startAt ? entity.startAt.toISOString() : null,
            endAt: entity.endAt ? entity.endAt.toISOString() : null,
            participants:
                entity.participants && entity.participants.length
                    ? convertToListOfOnlineParticipant(entity.participants)
                    : undefined,
            vote: entity.vote
                ? {
                      ...entity.vote,
                      dateEnvoi: entity.vote?.dateEnvoi
                          ? moment(entity.vote?.dateEnvoi).toDate()
                          : undefined,
                  }
                : null,
        } as unknown as SessionInformation,
        (v) => undefined === v
    );
};

测试结果与问题

测试结果见截图。Node.js日志里出现了错误:{"msg":"The server is too busy, dropping the request","time":"2023-07-26T06:18:38.634Z"},这个错误来自toobusy-js(没有做任何自定义配置)。

服务器配置

  • Node.js服务:基于Express框架,Debian系统,16vCPU、8GB内存,未启用Cluster模式,用pm2管理
  • PostgreSQL服务:Debian系统,5vCPU、4GB内存,未启用Cluster模式

根据相关性能文章,当前配置的性能不该这么差,恳请帮忙分析性能瓶颈的原因。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 09:52:42