{"action":"created","issue":{"url":"https://api.github.com/repos/team-tsukuba/isucon6q-test-rerost/issues/6","repository_url":"https://api.github.com/repos/team-tsukuba/isucon6q-test-rerost","labels_url":"https://api.github.com/repos/team-tsukuba/isucon6q-test-rerost/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/team-tsukuba/isucon6q-test-rerost/issues/6/comments","events_url":"https://api.github.com/repos/team-tsukuba/isucon6q-test-rerost/issues/6/events","html_url":"https://github.com/team-tsukuba/isucon6q-test-rerost/issues/6","id":263628863,"number":6,"title":"パフォーマンス","user":{"login":"rerost","id":5201588,"avatar_url":"https://avatars1.githubusercontent.com/u/5201588?v=4","gravatar_id":"","url":"https://api.github.com/users/rerost","html_url":"https://github.com/rerost","followers_url":"https://api.github.com/users/rerost/followers","following_url":"https://api.github.com/users/rerost/following{/other_user}","gists_url":"https://api.github.com/users/rerost/gists{/gist_id}","starred_url":"https://api.github.com/users/rerost/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rerost/subscriptions","organizations_url":"https://api.github.com/users/rerost/orgs","repos_url":"https://api.github.com/users/rerost/repos","events_url":"https://api.github.com/users/rerost/events{/privacy}","received_events_url":"https://api.github.com/users/rerost/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-10-07T09:23:34Z","updated_at":"2017-10-07T13:12:26Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"```\r\nOct 07 14:08:00 ubuntu-xenial bundle[6105]: lib/isuda/web.rb\r\nOct 07 14:08:00 ubuntu-xenial bundle[6105]:                |  77          salt = 1.upto(20).map { chars.sample }.join('')\r\nOct 07 14:08:00 ubuntu-xenial bundle[6105]:                |  78          salted_password = encode_with_salt(password: pw, salt: salt)\r\nOct 07 14:08:00 ubuntu-xenial bundle[6105]:    2.6ms     2 |  79          db.xquery(%|\r\nOct 07 14:08:00 ubuntu-xenial bundle[6105]:                |  80            INSERT INTO user (name, salt, password, created_at)\r\nOct 07 14:08:00 ubuntu-xenial bundle[6105]:                |  81            VALUES (?, ?, ?, NOW())\r\nOct 07 14:08:00 ubuntu-xenial bundle[6105]:               .......\r\nOct 07 14:08:00 ubuntu-xenial bundle[6105]:                |  182      end\r\nOct 07 14:08:00 ubuntu-xenial bundle[6105]:                |  183\r\nOct 07 14:08:00 ubuntu-xenial bundle[6105]:    3.0ms     1 |  184      post '/register' do\r\nOct 07 14:08:00 ubuntu-xenial bundle[6105]:                |  185        name = params[:name] || ''\r\nOct 07 14:08:00 ubuntu-xenial bundle[6105]:                |  186        pw   = params[:password] || ''\r\nOct 07 14:08:00 ubuntu-xenial bundle[6105]:                |  187        halt(400) if (name == '') || (pw == '')\r\nOct 07 14:08:00 ubuntu-xenial bundle[6105]:                |  188\r\nOct 07 14:08:00 ubuntu-xenial bundle[6105]:    2.7ms     1 |  189        user_id = register(name, pw)\r\nOct 07 14:08:00 ubuntu-xenial bundle[6105]:                |  190        session[:user_id] = user_id\r\nOct 07 14:08:00 ubuntu-xenial bundle[6105]:                |  191\r\n```\r\nこれだとSQLのinsertが遅い -> redis を使うか、innoDBあたりのキャッシュを増やせば良さそう・・・？\r\n\r\n```\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]: lib/isuda/web.rb\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  41          user_id = session[:user_id]\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  42          if user_id\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:    1.4ms     4 |  43            user = db.xquery(%| select name from user where id = ? |, user_id).first\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  44            @user_id = user_id\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  45            @user_name = user[:name]\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:               .......\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  50\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  51      set(:authenticate) do |value|\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:   12.1ms     1 |  52        condition {\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  53          halt(403) unless @user_id\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  54        }\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:               .......\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  61              _, _, attrs_part = settings.dsn.split(':', 3)\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  62              attrs = Hash[attrs_part.split(';').map {|part| part.split('=', 2) }]\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:    2.2ms     2 |  63              mysql = Mysql2::Client.new(\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  64                username: settings.db_user,\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  65                password: settings.db_password,\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:               .......\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  89\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  90        def is_spam_content(content)\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:    0.7ms     4 |  91          isupam_uri = URI(settings.isupam_origin)\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:   11.1ms     2 |  92          res = Net::HTTP.post_form(isupam_uri, 'content' => content)\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  93          validation = JSON.parse(res.body)\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  94          validation['valid']\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:               .......\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  216      end\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  217\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:    6.1ms     1 |  218      post '/keyword', set_name: true, authenticate: true do\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  219        keyword = params[:keyword] || ''\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  220        halt(400) if keyword == ''\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:               .......\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  223\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  224        bound = [@user_id, keyword, description] * 2\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:    2.2ms     2 |  225        db.xquery(%|\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  226          INSERT INTO entry (author_id, keyword, description, created_at, updated_at)\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  227          VALUES (?, ?, ?, NOW(), NOW())\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:               .......\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  230        |, *bound)\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  231\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:    0.2ms     1 |  232        redirect_found '/'\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  233      end\r\nOct 07 17:30:48 ubuntu-xenial bundle[6979]:                |  234\r\n```\r\n\r\n```\r\nOct 07 17:47:40 ubuntu-xenial bundle[6983]: [Rack::Lineprof] ===============================================================\r\nOct 07 17:47:40 ubuntu-xenial bundle[6983]: lib/isutar/web.rb\r\nOct 07 17:47:40 ubuntu-xenial bundle[6983]:                |  67        keyword = params[:keyword]\r\nOct 07 17:47:40 ubuntu-xenial bundle[6983]:                |  68\r\nOct 07 17:47:40 ubuntu-xenial bundle[6983]:    0.3ms     2 |  69        isuda_keyword_url = URI(settings.isuda_origin)\r\nOct 07 17:47:40 ubuntu-xenial bundle[6983]:                |  70        isuda_keyword_url.path = '/keyword/%s' % [Rack::Utils.escape_path(keyword)]\r\nOct 07 17:47:40 ubuntu-xenial bundle[6983]:  270.0ms     1 |  71        res = Net::HTTP.get_response(isuda_keyword_url)\r\nOct 07 17:47:40 ubuntu-xenial bundle[6983]:                |  72        halt(404) unless Net::HTTPSuccess === res\r\nOct 07 17:47:40 ubuntu-xenial bundle[6983]:                |  73\r\nOct 07 17:47:40 ubuntu-xenial bundle[6983]:                |  74        user_name = params[:user]\r\nOct 07 17:47:40 ubuntu-xenial bundle[6983]:    1.3ms     2 |  75        db.xquery(%|\r\nOct 07 17:47:40 ubuntu-xenial bundle[6983]:                |  76          INSERT INTO star (keyword, user_name, created_at)\r\nOct 07 17:47:40 ubuntu-xenial bundle[6983]:                |  77          VALUES (?, ?, NOW())\r\n```\r\n\r\n高速化できそうな部分\r\n- [ ] login\r\n  - [ ] login を redisで行う\r\n    - [ ] redisへの書き込み\r\n    - [ ] mysql への同期（再起動時にデータを保持している必要があるので）\r\n- [ ] keyword へのpost\r\n  - [ ] `condition`が遅いのはなぜ・・・？\r\n  - [ ] `URI`が遅いので事前にしておく\r\n  - [ ] 挿入が遅い\r\n- [ ] stars へのpost\r\n  - [x] keywordへ話しかけることは必要か\r\n    - [x] keyword の存在確認\r\n    - [ ] isutar の使うDBを isudaへ\r\n    - [ ] isutar を完全にisudaにまとめる\r\n"},"comment":{"url":"https://api.github.com/repos/team-tsukuba/isucon6q-test-rerost/issues/comments/334934211","html_url":"https://github.com/team-tsukuba/isucon6q-test-rerost/issues/6#issuecomment-334934211","issue_url":"https://api.github.com/repos/team-tsukuba/isucon6q-test-rerost/issues/6","id":334934211,"user":{"login":"rerost","id":5201588,"avatar_url":"https://avatars1.githubusercontent.com/u/5201588?v=4","gravatar_id":"","url":"https://api.github.com/users/rerost","html_url":"https://github.com/rerost","followers_url":"https://api.github.com/users/rerost/followers","following_url":"https://api.github.com/users/rerost/following{/other_user}","gists_url":"https://api.github.com/users/rerost/gists{/gist_id}","starred_url":"https://api.github.com/users/rerost/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rerost/subscriptions","organizations_url":"https://api.github.com/users/rerost/orgs","repos_url":"https://api.github.com/users/rerost/repos","events_url":"https://api.github.com/users/rerost/events{/privacy}","received_events_url":"https://api.github.com/users/rerost/received_events","type":"User","site_admin":false},"created_at":"2017-10-07T13:12:26Z","updated_at":"2017-10-07T13:12:26Z","author_association":"CONTRIBUTOR","body":"top ページのhtmplifyを最適化する\r\n- [ ] 取得するカラムの最小化\r\n- [ ] 文字数、Regexpを事前に計算してしまう"}}
{"actor":{"display_login":"rerost"}}