NutzCN Logo
问答 用户登录异常缓慢,有没有调优的方法?
发布于 2210天前 作者 liumaobudao 2258 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

如题用户登录的时候异常缓慢,内存8G的服务器,登录超过10秒。发现控制台刷新大量的shiro 菜单信息。。。而且每次登录都会刷新,想问一下有没有什么可以调优的方法?

For example:> "select distinct a.* from sys_menu a,sys_role_menu b where a.id=b.menuId and  b.roleId in(select c.roleId from sys_user_role c,sys_role d where c.roleId=d.id and c.userId='a311c77170774b3682b66eaba9757bab' and d.disabled=false) and a.disabled=false and a.isShow=true and a.type='menu' order by a.location ASC,a.path asc"
[DEBUG] 2018-09-15 11:19:45,457 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - SELECT * FROM sys_menu  WHERE id IN (?,?)
    |                                1 |                                2 |
    |----------------------------------|----------------------------------|
    | 003252023f6944b8b303e8a69a21978c | 4c0cdfc7ae164292a86e97951d64dbc5 |
  For example:> "SELECT * FROM sys_menu  WHERE id IN ('003252023f6944b8b303e8a69a21978c','4c0cdfc7ae164292a86e97951d64dbc5')"
[DEBUG] 2018-09-15 11:19:45,495 org.apache.shiro.realm.AuthenticatingRealm.getAuthenticationInfo(AuthenticatingRealm.java:569) - Looked up AuthenticationInfo [/*cn.wizzer.app.sys.modules.models.Sys_user@3c424cf8*/{"id":"a311c77170774b3682b66eaba9757bab","loginname":"superadmin","password":"IlhnXgS63PwbrjOx5WlVu3Jfhg7hSRnE0ZcsRcFnLRE=","salt":"Z0BjYJIY8kEoxvSBEJ1mKQ==","username":"ӬܶڜmԱ","isOnline":true,"disabled":false,"loginAt":1536892848,"loginIp":"127.0.0.1","loginCount":2875,"customMenu":"003252023f6944b8b303e8a69a21978c,4c0cdfc7ae164292a86e97951d64dbc5","loginTheme":"palette.css","proinputyear":"2018","loginSidebar":false,"loginBoxed":false,"loginScroll":false,"loginPjax":false,"unitid":"268281f0f357429889c659f13e337627","unit":{"id":"268281f0f357429889c659f13e337627","parentId":"0bf8f4718dd4464bb452c1a582ac7d0a","path":"00010003","name":"ɋ˂Ԧ","unitcode":"rsc01","type":"col","location":186,"hasChildren":false,"opBy":"a311c77170774b3682b66eaba9757bab","opAt":1530153918,"delFlag":false},"roles":[{"id":"4qkdtr1dokherq39pg3e3m5tbn","name":"ܹѾ״̬˽ߝࠢ2018_1-7_өߴ","code":"bdbview_3b920187446342f4b3ba038e8dae72c8","disabled":false,"note":"ҭ1-7ѾࠆʺܹѾȩ࠶èѧŪé","opAt":1533203034,"delFlag":false}, {"id":"88ac2a6a312949ddb331d452d06a414f","name":"ϵͳڜmԱ","code":"sysadmin","aliasName":"Sysadmin","disabled":false,"note":"System Admin","opAt":1510138358,"delFlag":false}],"units":[],"menus":[{"id":"673030089e46427086f5b3eefc8b746c","path":"0001","name":"ϵͳ","aliasName":"System","type":"menu","isShow":true,"disabled":false,"permission":"sys","note":"ϵͳ","location":67,"hasChildren":true,"opAt":1510138357,"delFlag":false}, {"id":"094fc1ab5d8c49259acf2574d562ae3d","parentId":"673030089e46427086f5b3eefc8b746c","path":"00010001","name":"ϵͳڜm","aliasName":"Manager","type":"menu","icon":"fa fa-cog","isShow":true,"disabled":false,"permission":"sys.manager","note":"ϵͳڜm","location":68,"hasChildren":true,"opBy":"a311c77170774b3682b66eaba9757bab","opAt":1536288677,"delFlag":false}, {"id":"0831d4a248a443998169d21e9a205417","parentId":"094fc1ab5d8c49259acf2574d562ae3d","path":"000100010001","name":"եλڜm","aliasName":"Unit","type":"menu","href":"/platform/sys/unit","target":"data-pjax","isShow":true,"disabled":false,"permission":"sys.manager.unit","location":341,"hasChildren":false,"opAt":1510138357,"delFlag":false}, {"id":"6e5c0ad1eefa426db962abb31ea2ff92","parentId":"094fc1ab5d8c49259acf2574d562ae3d","path":"000100010002","name":"ԃۧڜm","aliasName":"User","type":"menu","href":"/platform/sys/user","target":"data-pjax","isShow":true,"disabled":false,"permission":"sys.manager.user","location":342,"hasChildren":false,"opAt":1510138357,"delFlag":false}, {"id":"9f4fc2cbc78a4e47b57868fe889ddc59","parentId":"094fc1ab5d8c49259acf2574d562ae3d","path":"000100010003","name":"އɫڜm","aliasName":"Role","type":"menu","href":"/platform/sys/role","target":"data-pjax","isShow":true,"disabled":false,"permission":"sys.manager.role","location":343,"hasChildren":false,"opAt":1510138357,"delFlag":false}, {"id":"faa9f0d2fdc04bf1bc56ab8642d0de76","parentId":"094fc1ab5d8c49259acf2574d562ae3d","path":"000100010004","name":"Ӌեڜm","aliasName":"Menu","type":"menu","href":"/platform/sys/menu","target":"data-pjax","isShow":true,"disabled":false,"permission":"sys.manager.menu","location":344,"hasChildren":false,"opAt":1510138358,"delFlag":false}, {"id":"bae413b8e3b84047a3a14b07b072725f","parentId":"094fc1ab5d8c49259acf2574d562ae3d","path":"000100010005","name":"ϵͳӎ˽","aliasName":"Param","type":"menu","href":"/platform/sys/conf","target":"data-pjax","isShow":true,"disabled":false,"permission":"sys.manager.conf","location":345,"hasChildren":false,"opAt":1510138358,"delFlag":false}, {"id":"b39c537b30094d899b76b5b8a8d9ff4d","parentId":"094fc1ab5d8c49259acf2574d562ae3d","path":"000100010006","name":"ɕ־ڜm","aliasName":"Log","type":"menu","href":"/platform/sys/log","target":"data-pjax","isShow":true,"disabled":false,"permission":"sys.manager.log","location":346,"hasChildren":false,"opAt":1510138358,"delFlag":false}, {"id":"13d3dcc2fc9948e19c6c78c35fe3a633","parentId":"094fc1ab5d8c49259acf2574d562ae3d","path":"000100010008","name":"ؔ֨ӥ·ԉ","aliasName":"Route","type":"menu","href":"/platform/sys/route","target":"data-pjax","isShow":true,"disabled":false,"permission":"sys.manager.route","location":349,"hasChildren":false,"opAt":1510138358,"delFlag":false}, {"id":"4389469ca7474d77bda7dd997f2e309c","parentId":"094fc1ab5d8c49259acf2574d562ae3d","path":"000100010010","name":"˽ߝ֤ؖ","aliasName":"Dict","type":"menu","href":"/platform/sys/dict","target":"data-pjax","isShow":true,"disabled":false,"permission":"sys.manager.dict","location":351,"hasChildren":false,"opAt":1510138358,"delFlag":false}, {"id":"7c8412daf6f34e72a4e75959c26527cf","parentId":"094fc1ab5d8c49259acf2574d562ae3d","path":"000100010012","name":"˽ߝԴڜm","aliasName":"DbManager","type":"menu","href":"/platform/sys/database","target":"data-pjax","isShow":true,"disabled":false,"permission":"platform.sys.database","location":353,"hasChildren":false,"opBy":"a311c77170774b3682b66eaba9757bab","opAt":1511163467,"delFlag":false}, {"id":"7448491544e544b48e5cb3864e6e3c2f","parentId":"094fc1ab5d8c49259acf2574d562ae3d","path":"000100010017","name":"BI·޶Ƥ׃","type":"menu","href":"/platform/sys/smartbiurlconfig","target":"data-pjax","isShow":true,"disabled":false,"permission":"platform.sys.smartbiurlconfig","location":357,"hasChildren":true,"opBy":"a311c77170774b3682b66eaba9757bab","opAt":1535352794,"delFlag":false}, {"id":"9d65d2471b984223ba86d25f31346699","parentId":"673030089e46427086f5b3eefc8b746c","path":"00010002","name":"ϵͳ˽ߝڜm","aliasName":"FileSystem","type":"menu","target":"data-pjax","icon":"fa fa-cogs","isShow":true,"disabled":false,"permission":"platform.sys.db","location":358,"hasChildren":true,"opBy":"a311c77170774b3682b66eaba9757bab","opAt":1536198630,"delFlag":false}, {"id":"b3fe315ebf0341559f129fe52b19c8a3","parentId":"9d65d2471b984223ba86d25f31346699","path":"000100020005","name":"˽ߝܯڜm","type":"menu","href":"/platform/sys/selectsqls","target":"data-pjax","isShow":true,"disabled":false,"permission":"platform.sys.selectsqls","location":374,"hasChildren":false,"opBy":"a311c77170774b3682b66eaba9757bab","opAt":1527129133,"delFlag":false}, {"id":"4eba2a02ec1349efafc96a0f8a5f7487","path":"0011","name":"ܹѾ״̬˽ߝࠢ","aliasName":"ܹѾ״̬˽ߝࠢ2018","type":"menu","isShow":true,"disabled":false,"permission":"7ff8c17eac3f47009acc886e21a85e21","location":417,"hasChildren":true,"opBy":"a311c77170774b3682b66eaba9757bab","opAt":1531101161,"delFlag":false}, {"id":"fc12387754b04f2285462bd7ba47110d","parentId":"dd6fe19518f04213bd1f7d7c30925b22","path":"001100020001","name":"ҭ1-1ѧУم࠶èʱ֣é","aliasName":"ҭ1-1ѧУم࠶èʱ֣é","type":"menu","href":"/platform/sys/tableview/viewindex/e281e5e93aa44501b2f0f7100dfea783","isShow":true,"disabled":false,"permission":"e281e5e93aa44501b2f0f7100dfea783","location":644,"hasChildren":false,"opBy":"a311c77170774b3682b66eaba9757bab","opAt":1531186458,"delFlag":false}, {"id":"e4f0bf8506cd47738642ae39283e82e7","parentId":"dd6fe19518f04213bd1f7d7c30925b22","path":"001100020002","name":"ҭ1-2Уȸַܰ֘èʱ֣é","aliasName":"ҭ1-2Уȸַܰ֘èʱ֣é","type":"menu","href":"/platform/sys/tableview/viewindex/3d86c1b52d3045a29414cdcd7fe0e1e7","isShow":true,"disabled":false,"permission":"3d86c1b52d3045a29414cdcd7fe0e1e7","location":645,"hasChildren":false,"opBy":"a311c77170774b3682b66eaba9757bab","opAt":1531186464,"delFlag":false}, 
8 回复

走索引了吗?数据量多少,即使全表扫描应该也没多少数据的样子

@wendal 走了索引的。。。才1000多条数据,不过数据库是oracle xe。。。

这sql在数据库控制台跑耗时多久

@wendal 1秒不到 应该不是 sql的问题

    public final AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {

        AuthenticationInfo info = getCachedAuthenticationInfo(token);
        if (info == null) {
            //otherwise not cached, perform the lookup:
            info = doGetAuthenticationInfo(token);
            log.debug("Looked up AuthenticationInfo [{}] from doGetAuthenticationInfo", info);//看代码   貌似是    执行这个log的时候相当的慢。。。。。。
            if (token != null && info != null) {
                cacheAuthenticationInfoIfPossible(token, info);
            }
        } else {
            log.debug("Using cached authentication info [{}] to perform credentials matching.", info);
        }

        if (info != null) {
            assertCredentialsMatch(token, info);
        } else {
            log.debug("No AuthenticationInfo found for submitted AuthenticationToken [{}].  Returning null.", token);
        }

        return info;
    }

自己来吧,应该是服务器性能跟不上 最后修改了shiro 相关 jar 包代码,所有log输出都取消掉了
路径 org.apache.shiro.realm.AuthenticatingRealm.java

   public final AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {

        AuthenticationInfo info = getCachedAuthenticationInfo(token);
        if (info == null) {
            //otherwise not cached, perform the lookup:
            info = doGetAuthenticationInfo(token);
         //   log.debug("Looked up AuthenticationInfo [{}] from doGetAuthenticationInfo", info);
            if (token != null && info != null) {
                cacheAuthenticationInfoIfPossible(token, info);
            }
        } else {
          //  log.debug("Using cached authentication info [{}] to perform credentials matching.", info);
        }

        if (info != null) {
            assertCredentialsMatch(token, info);
        } else {
       //     log.debug("No AuthenticationInfo found for submitted AuthenticationToken [{}].  Returning null.", token);
        }

        return info;
    }
    private void cacheAuthenticationInfoIfPossible(AuthenticationToken token, AuthenticationInfo info) {
        if (!isAuthenticationCachingEnabled(token, info)) {
      //      log.debug("AuthenticationInfo caching is disabled for info [{}].  Submitted token: [{}].", info, token);
            //return quietly, caching is disabled for this token/info pair:
            return;
        }

        Cache<Object, AuthenticationInfo> cache = getAvailableAuthenticationCache();
        if (cache != null) {
            Object key = getAuthenticationCacheKey(token);
            cache.put(key, info);
     //       log.trace("Cached AuthenticationInfo for continued authentication.  key=[{}], value=[{}].", key, info);
        }
    }

org.apache.shiro.authc.AbstractAuthenticator.java

    public final AuthenticationInfo authenticate(AuthenticationToken token) throws AuthenticationException {

        if (token == null) {
            throw new IllegalArgumentException("Method argument (authentication token) cannot be null.");
        }

        log.trace("Authentication attempt received for token [{}]", token);

        AuthenticationInfo info;
        try {
            info = doAuthenticate(token);
            if (info == null) {
                String msg = "No account information found for authentication token [" + token + "] by this " +
                        "Authenticator instance.  Please check that it is configured correctly.";
                throw new AuthenticationException(msg);
            }
        } catch (Throwable t) {
            AuthenticationException ae = null;
            if (t instanceof AuthenticationException) {
                ae = (AuthenticationException) t;
            }
            if (ae == null) {
                //Exception thrown was not an expected AuthenticationException.  Therefore it is probably a little more
                //severe or unexpected.  So, wrap in an AuthenticationException, log to warn, and propagate:
                String msg = "Authentication failed for token submission [" + token + "].  Possible unexpected " +
                        "error? (Typical or expected login exceptions should extend from AuthenticationException).";
                ae = new AuthenticationException(msg, t);
                if (log.isWarnEnabled())
                    log.warn(msg, t);
            }
            try {
                notifyFailure(token, ae);
            } catch (Throwable t2) {
                if (log.isWarnEnabled()) {
                    String msg = "Unable to send notification for failed authentication attempt - listener error?.  " +
                            "Please check your AuthenticationListener implementation(s).  Logging sending exception " +
                            "and propagating original AuthenticationException instead...";
                    log.warn(msg, t2);
                }
            }


            throw ae;
        }

   //     log.debug("Authentication successful for token [{}].  Returned account [{}]", token, info);

        notifySuccess(token, info);

        return info;
    }

日志导致慢??

可以把Sys_User的toString方法改一下嘛

@wendal 确实是log.debug导致的慢 注销过后,登录速度变回正常1秒。

添加回复
请先登陆
回到顶部