Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

友達判定に時間がかかってる #3

Open
ysakasin opened this issue Oct 9, 2017 · 3 comments
Open

友達判定に時間がかかってる #3

ysakasin opened this issue Oct 9, 2017 · 3 comments

Comments

@ysakasin
Copy link
Member

ysakasin commented Oct 9, 2017

ROUTINE ======================== main.isFriend in /home/isucon/webapp/go/app.go
         0      6.60s (flat, cum) 43.22% of Total
         .          .    152:    checkErr(err)
         .          .    153:    return &user
         .          .    154:}
         .          .    155:
         .          .    156:func isFriend(w http.ResponseWriter, r *http.Request, anotherID int) bool {
         .      200ms    157:    session := getSession(w, r)
         .       10ms    158:    id := session.Values["user_id"]
         .      4.82s    159:    row := db.QueryRow(`SELECT COUNT(1) AS cnt FROM relations WHERE (one = ? AND another = ?) OR (one = ? AND another = ?)`, id, anotherID, anotherID, id)
         .          .    160:    cnt := new(int)
         .      1.57s    161:    err := row.Scan(cnt)
         .          .    162:    checkErr(err)
         .          .    163:    return *cnt > 0
         .          .    164:}
         .          .    165:
         .          .    166:func isFriendAccount(w http.ResponseWriter, r *http.Request, name string) bool {
@ysakasin
Copy link
Member Author

ysakasin commented Oct 9, 2017

Redisによるキャッシュを試したが、あまり効果は出なかった。そもそもMySQLなりRedisなりへのアクセス回数を削減しないとだめそう

@ysakasin
Copy link
Member Author

ysakasin commented Oct 9, 2017

次にとれる策

  • Redisに関係の情報を扱いやすいように変形して全て載せる
  • MySQLをつかうようにしてクエリ発行回数を減らす

@ysakasin
Copy link
Member Author

SQLクエリ削減 310d678

Benchmark passed. ❤️
Score: 2379.1000

  • Success: 2314
  • Fail: 1
  • Error: 0
  • Exception: 0
  • Redirect: 651

標準実装からbranchきったので、約1000点gain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant