wso2 api管理器对store rest api执行缓慢的sql查询,导致ui性能不佳

5f0d552i  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(294)

部署如下:
mgr节点:默认(存储+发布),网关管理器。
工人节点:gw工人、关键管理者
我们使用mysql ndb作为api管理器数据库。在商店ui上观察到非常慢的api加载时间。使用chrome开发工具,我看到当单击api打开时(使用登录会话)将调用以下api:
http://{host/port}/store/api/info?name={api name}&version={v}&provider={provider}
在我们的负载平衡器(504)上手动调用api(包括cookie)超时。在store jaggery文件中,我找到了它似乎调用的api(../repository/deplyement/server/jaggeryapps/store/modules/api/api.jag),但是我无法将它与实际的api impl联系起来。根据常识,我认为需要从数据库中检索api及其相关元数据。
启用慢速查询日志(25)会生成以下查询,当我尝试打开api时会记录该查询:

SELECT
  ICA.CONSUMER_KEY AS CONSUMER_KEY,
  ICA.CONSUMER_SECRET AS CONSUMER_SECRET,
  IAT.ACCESS_TOKEN AS ACCESS_TOKEN,
  IAT.VALIDITY_PERIOD AS VALIDITY_PERIOD,
  ISAT.TOKEN_SCOPE AS TOKEN_SCOPE,
  AKM.KEY_TYPE AS TOKEN_TYPE,
  AKM.STATE AS STATE
FROM
  AM_APPLICATION_KEY_MAPPING AKM,
  IDN_OAUTH2_ACCESS_TOKEN IAT,
  IDN_OAUTH2_ACCESS_TOKEN_SCOPE ISAT,
  IDN_OAUTH_CONSUMER_APPS ICA
WHERE AKM.APPLICATION_ID = 149
  AND IAT.USER_TYPE = 'APPLICATION'
  AND ICA.CONSUMER_KEY = AKM.CONSUMER_KEY
  AND IAT.CONSUMER_KEY_ID = ICA.ID
  AND IAT.TOKEN_ID = ISAT.TOKEN_ID
  AND AKM.KEY_TYPE = 'PRODUCTION'
  AND (
    IAT.TOKEN_STATE = 'ACTIVE'
    OR IAT.TOKEN_STATE = 'EXPIRED'
    OR IAT.TOKEN_STATE = 'REVOKED'
  )
ORDER BY IAT.TIME_CREATED DESC;

这个查询平均需要80次执行,返回大约33000行。由于没有联接,查询编写得很差,下面的优化版本在<3s中返回相同的结果集:

SELECT
  `api_am_dev_1`.`ICA`.`CONSUMER_KEY` AS `CONSUMER_KEY`,
  `api_am_dev_1`.`ICA`.`CONSUMER_SECRET` AS `CONSUMER_SECRET`,
  `api_am_dev_1`.`IAT`.`ACCESS_TOKEN` AS `ACCESS_TOKEN`,
  `api_am_dev_1`.`IAT`.`VALIDITY_PERIOD` AS `VALIDITY_PERIOD`,
  `api_am_dev_1`.`ISAT`.`TOKEN_SCOPE` AS `TOKEN_SCOPE`,
  `api_am_dev_1`.`AKM`.`KEY_TYPE` AS `TOKEN_TYPE`,
  `api_am_dev_1`.`AKM`.`STATE` AS `STATE`
FROM
  `api_am_dev_1`.`AM_APPLICATION_KEY_MAPPING` `AKM`
  JOIN `api_am_dev_1`.`IDN_OAUTH2_ACCESS_TOKEN` `IAT`
  JOIN `api_am_dev_1`.`IDN_OAUTH2_ACCESS_TOKEN_SCOPE` `ISAT`
  JOIN `api_am_dev_1`.`IDN_OAUTH_CONSUMER_APPS` `ICA`
WHERE (
    (
      `api_am_dev_1`.`AKM`.`KEY_TYPE` = 'PRODUCTION'
    )
    AND (
      `api_am_dev_1`.`ISAT`.`TOKEN_ID` = `api_am_dev_1`.`IAT`.`TOKEN_ID`
    )
    AND (
      `api_am_dev_1`.`IAT`.`CONSUMER_KEY_ID` = `api_am_dev_1`.`ICA`.`ID`
    )
    AND (
      `api_am_dev_1`.`ICA`.`CONSUMER_KEY` = `api_am_dev_1`.`AKM`.`CONSUMER_KEY`
    )
    AND (
      `api_am_dev_1`.`IAT`.`USER_TYPE` = 'APPLICATION'
    )
    AND (
      `api_am_dev_1`.`AKM`.`APPLICATION_ID` = 149
    )
    AND (
      (
        `api_am_dev_1`.`IAT`.`TOKEN_STATE` = 'ACTIVE'
      )
      OR (
        `api_am_dev_1`.`IAT`.`TOKEN_STATE` = 'EXPIRED'
      )
      OR (
        `api_am_dev_1`.`IAT`.`TOKEN_STATE` = 'REVOKED'
      )
    )
  )
ORDER BY `api_am_dev_1`.`IAT`.`TIME_CREATED` DESC

添加索引似乎无助于解决这个问题。我们每周进行一次令牌清理,所以数据库中总共只有大约20000个令牌~我们的qa非常忙。
问题:查询是由hibernate生成的,并且是创建补丁的唯一选项吗?
wso2商店是一个很棒的开发人员门户,但这正在破坏我们许多用户的体验。
编辑:
api管理器版本=2.1.0

qcuzuvrc

qcuzuvrc1#

答案是否定的,查询不是由hibernate或任何其他抽象框架生成的。所有的查询都作为字符串常量存储在java类文件中,因此是的,如果您发现需要更改底层查询,您必须更改查询并构建修补程序。
我们遇到了同样的问题,但添加以下索引可以显著提高单击api检索其信息时的存储性能:
数据库:apimgt
表:idn\U oauth2\U访问\U令牌
列:用户\类型、使用者\密钥\ id、令牌\ id、令牌\状态

相关问题