saza-ku / isucon13

0 stars 0 forks source link

11250556 #48

Open saza-ku opened 1 year ago

saza-ku commented 1 year ago

isucon1

alp

+-------+--------+------------------------------------------+-------+-------+-------+-------+-------+
| COUNT | METHOD |                   URI                    |  MIN  |  MAX  |  SUM  |  AVG  |  P99  |
+-------+--------+------------------------------------------+-------+-------+-------+-------+-------+
| 12    | GET    | /api/livestream/.+                       | 0.008 | 0.256 | 2.052 | 0.171 | 0.256 |
| 22    | POST   | /api/livestream/.+                       | 0.012 | 0.016 | 0.312 | 0.014 | 0.016 |
| 42    | GET    | /api/livestream/.+/reaction              | 0.004 | 0.008 | 0.152 | 0.004 | 0.008 |
| 4     | GET    | /api/livestream                          | 0.016 | 0.048 | 0.128 | 0.032 | 0.048 |
| 24    | POST   | /api/livestream/.+/reaction              | 0.004 | 0.008 | 0.100 | 0.004 | 0.008 |
| 2     | POST   | /api/register                            | 0.036 | 0.040 | 0.076 | 0.038 | 0.040 |
| 2     | GET    | /api/user/.+/statistics                  | 0.028 | 0.032 | 0.060 | 0.030 | 0.032 |
| 2     | GET    | /api/livestream/.+/statistics            | 0.024 | 0.028 | 0.052 | 0.026 | 0.028 |
| 3     | POST   | /api/livestream/.+/livecomment           | 0.008 | 0.008 | 0.024 | 0.008 | 0.008 |
| 7     | POST   | /api/login                               | 0.004 | 0.004 | 0.012 | 0.002 | 0.004 |
| 2     | POST   | /api/livestream/.+/livecomment/.+/report | 0.004 | 0.004 | 0.008 | 0.004 | 0.004 |
| 3     | GET    | /api/tag                                 | 0.000 | 0.004 | 0.004 | 0.001 | 0.004 |
| 4     | GET    | /api/user/.+                             | 0.000 | 0.004 | 0.004 | 0.001 | 0.004 |
| 4     | GET    | /api/user/.+/icon                        | 0.000 | 0.004 | 0.004 | 0.001 | 0.004 |
| 1     | GET    | /api/payment                             | 0.004 | 0.004 | 0.004 | 0.004 | 0.004 |
| 2     | POST   | /api/icon                                | 0.000 | 0.004 | 0.004 | 0.002 | 0.004 |
| 2     | POST   | /api/livestream/.+/enter                 | 0.000 | 0.004 | 0.004 | 0.002 | 0.004 |
| 1     | GET    | /api/livestream/.+/livecomment           | 0.004 | 0.004 | 0.004 | 0.004 | 0.004 |
| 1     | DELETE | /api/livestream/.+/exit                  | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 |
| 1     | GET    | /api/user/.+/theme                       | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 |
| 1     | GET    | /api/livestream/.+/report                | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 |
+-------+--------+------------------------------------------+-------+-------+-------+-------+-------+

slow query

explain

Reading from STDIN ...

# No events processed.

netdata

http://localhost:19991/#menu_services;after=1700891764203;before=1700891840269

pprof

go tool pprof -http=0.0.0.0:1080 http://isucon1/pprof/11250556
saza-ku commented 1 year ago

isucon2

alp

+-------+--------+-----+-----+-----+-----+-----+-----+
| COUNT | METHOD | URI | MIN | MAX | SUM | AVG | P99 |
+-------+--------+-----+-----+-----+-----+-----+-----+
+-------+--------+-----+-----+-----+-----+-----+-----+

slow query

Count: 73  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=0.8 (62), isudns[isudns]@isucon1
  SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM records WHERE disabled=N and name='S' and domain_id=N

Count: 70  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=0.5 (36), isudns[isudns]@isucon1
  SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM records WHERE disabled=N and type='S' and name='S'

Count: 74  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=0.0 (0), isudns[isudns]@isucon1
  select kind,content from domains, domainmetadata where domainmetadata.domain_id=domains.id and name='S'

Count: 209  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=0.0 (0), isudns[isudns]@isucon1
  #

Count: 2  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=0.0 (0), isudns[isudns]@isucon1
  delete from records where domain_id=N and name='S' and type='S'

Count: 4  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=0.5 (2), isudns[isudns]@isucon1
  SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM records WHERE disabled=N and type='S' and name='S' and domain_id=N

Count: 2  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=1.0 (2), isudns[isudns]@isucon1
  select id,name,master,last_check,notified_serial,type,options,catalog,account from domains where name='S'

Count: 2  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=0.0 (0), isudns[isudns]@isucon1
  insert into records (content,ttl,prio,type,domain_id,disabled,name,ordername,auth) values ('S',N,N,'S',N,N,'S',NULL,N)

Count: 2  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=0.0 (0), isudns[isudns]@isucon1
  commit

Count: 4  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=0.0 (0), isudns[isudns]@isucon1
  SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED

explain

Reading from STDIN ...

# 170ms user time, 10ms system time, 36.25M rss, 50.68M vsz
# Current date: Sat Nov 25 05:57:24 2023
# Hostname: ip-192-168-0-12
# Files: STDIN
# Overall: 451 total, 20 unique, 5.64 QPS, 0.00x concurrency _____________
# Time range: 2023-11-25T05:56:04 to 2023-11-25T05:57:24
# Attribute          total     min     max     avg     95%  stddev  median
# ============     ======= ======= ======= ======= ======= ======= =======
# Exec time          143ms     1us     4ms   318us   799us   451us    80us
# Lock time          248us       0     4us       0     1us       0       0
# Rows sent            106       0       1    0.24    0.99    0.42       0
# Rows examine     186.35k       0   1.25k  423.12   1.20k  578.93       0
# Query size        35.17k       5     195   79.86  136.99   47.52  112.70

# Profile
# Rank Query ID                        Response time Calls R/Call V/M   It
# ==== =============================== ============= ===== ====== ===== ==
#    1 0x42EF7D7D98FBCC9723BF896EBF...  0.0620 43.2%    73 0.0008  0.00 SELECT records
#    2 0x3D83BC87F3B3A00D571FFC8104...  0.0578 40.3%    70 0.0008  0.00 SELECT records
#    3 0x22279D81D51006139E0C76405B...  0.0078  5.4%    74 0.0001  0.00 SELECT domains domainmetadata
#    4 0xE77769C62EF669AA7DD5F6760F...  0.0049  3.4%     2 0.0024  0.00 SHOW VARIABLES
# MISC 0xMISC                           0.0109  7.6%   232 0.0000   0.0 <16 ITEMS>

# Query 1: 14.60 QPS, 0.01x concurrency, ID 0x42EF7D7D98FBCC9723BF896EBFC51D24 at byte 15910
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: 2023-11-25T05:56:04 to 2023-11-25T05:56:09
# Attribute    pct   total     min     max     avg     95%  stddev  median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count         16      73
# Exec time     43    62ms   702us     2ms   849us     2ms   351us   725us
# Lock time     26    65us       0     2us       0     1us       0     1us
# Rows sent     58      62       0       1    0.85    0.99    0.35    0.99
# Rows examine  48  91.30k   1.25k   1.25k   1.25k   1.20k       0   1.20k
# Query size    27   9.57k     129     144  134.23  143.84    4.40  130.47
# String:
# Hosts        isucon1
# Users        isudns
# Query_time distribution
#   1us
#  10us
# 100us  ################################################################
#   1ms  ######
#  10ms
# 100ms
#    1s
#  10s+
# Tables
#    SHOW TABLE STATUS LIKE 'records'\G
#    SHOW CREATE TABLE `records`\G
# EXPLAIN /*!50100 PARTITIONS*/
SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM records WHERE disabled=0 and name='qotd.u.isucon.dev' and domain_id=4\G
# EXPLAIN failed: DBD::mysql::st execute failed: Table 'isupipe.records' doesn't exist [for Statement "EXPLAIN SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM records WHERE disabled=0 and name='qotd.u.isucon.dev' and domain_id=4"] at /usr/bin/pt-query-digest line 7796.

# Query 2: 14 QPS, 0.01x concurrency, ID 0x3D83BC87F3B3A00D571FFC8104A6E50C at byte 14209
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: 2023-11-25T05:56:04 to 2023-11-25T05:56:09
# Attribute    pct   total     min     max     avg     95%  stddev  median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count         15      70
# Exec time     40    58ms   662us     2ms   826us     1ms   305us   690us
# Lock time     32    81us       0     3us     1us     1us       0     1us
# Rows sent     33      36       0       1    0.51    0.99    0.50    0.99
# Rows examine  46  87.55k   1.25k   1.25k   1.25k   1.20k       0   1.20k
# Query size    25   8.86k     126     143  129.61  136.99    4.35  124.25
# String:
# Hosts        isucon1
# Users        isudns
# Query_time distribution
#   1us
#  10us
# 100us  ################################################################
#   1ms  #########
#  10ms
# 100ms
#    1s
#  10s+
# Tables
#    SHOW TABLE STATUS LIKE 'records'\G
#    SHOW CREATE TABLE `records`\G
# EXPLAIN 
SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM records WHERE disabled=0 and type='SOA' and name='u.isucon.dev'\G
# EXPLAIN failed: DBD::mysql::st execute failed: Table 'isupipe.records' doesn't exist [for Statement "EXPLAIN SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM records WHERE disabled=0 and type='SOA' and name='u.isucon.dev'"] at /usr/bin/pt-query-digest line 7796.

# Query 3: 14.80 QPS, 0.00x concurrency, ID 0x22279D81D51006139E0C76405B54C261 at byte 16486
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: 2023-11-25T05:56:04 to 2023-11-25T05:56:09
# Attribute    pct   total     min     max     avg     95%  stddev  median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count         16      74
# Exec time      5     8ms    75us   319us   105us   159us    35us    93us
# Lock time     35    88us     1us     2us     1us     1us       0     1us
# Rows sent      0       0       0       0       0       0       0       0
# Rows examine   0       0       0       0       0       0       0       0
# Query size    23   8.24k     114     114     114     114       0     114
# String:
# Hosts        isucon1
# Users        isudns
# Query_time distribution
#   1us
#  10us  ################################################################
# 100us  ###########################################
#   1ms
#  10ms
# 100ms
#    1s
#  10s+
# Tables
#    SHOW TABLE STATUS LIKE 'domains'\G
#    SHOW CREATE TABLE `domains`\G
#    SHOW TABLE STATUS LIKE 'domainmetadata'\G
#    SHOW CREATE TABLE `domainmetadata`\G
# EXPLAIN 
select kind,content from domains, domainmetadata where domainmetadata.domain_id=domains.id and name='u.isucon.dev'\G
# EXPLAIN failed: DBD::mysql::st execute failed: Table 'isupipe.domains' doesn't exist [for Statement "EXPLAIN select kind,content from domains, domainmetadata where domainmetadata.domain_id=domains.id and name='u.isucon.dev'"] at /usr/bin/pt-query-digest line 7796.

# Query 4: 0 QPS, 0x concurrency, ID 0xE77769C62EF669AA7DD5F6760F2D2EBB at byte 126663
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: all events occurred at 2023-11-25T05:57:24
# Attribute    pct   total     min     max     avg     95%  stddev  median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count          0       2
# Exec time      3     5ms   917us     4ms     2ms     4ms     2ms     2ms
# Lock time      2     5us     1us     4us     2us     4us     2us     2us
# Rows sent      1       2       1       1       1       1       0       1
# Rows examine   0       2       1       1       1       1       0       1
# Query size     0      77      35      42   38.50      42    4.95   38.50
# String:
# Databases    isupipe
# Hosts        localhost
# Users        isucon
# Query_time distribution
#   1us
#  10us
# 100us  ################################################################
#   1ms  ################################################################
#  10ms
# 100ms
#    1s
#  10s+
SHOW VARIABLES LIKE 'wait\_timeout'\G

netdata

http://localhost:19992/#menu_services;after=1700891764210;before=1700891844218

pprof

go tool pprof -http=0.0.0.0:1080 http://isucon2/pprof/11250556
saza-ku commented 1 year ago

isucon3

alp

+-------+--------+-----+-----+-----+-----+-----+-----+
| COUNT | METHOD | URI | MIN | MAX | SUM | AVG | P99 |
+-------+--------+-----+-----+-----+-----+-----+-----+
+-------+--------+-----+-----+-----+-----+-----+-----+

slow query

Count: 1273  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=1.0 (1273), isucon[isucon]@isucon1
  SELECT * FROM themes WHERE user_id = N

Count: 22  Time=0.01s (0s)  Lock=0.00s (0s)  Rows=0.0 (0), isucon[isucon]@isucon1
  UPDATE reservation_slots SET slot = slot - N WHERE start_at >= N AND end_at <= N

Count: 22  Time=0.01s (0s)  Lock=0.00s (0s)  Rows=1.3 (28), isucon[isucon]@isucon1
  SELECT * FROM reservation_slots WHERE start_at >= N AND end_at <= N FOR UPDATE

Count: 2119  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=1.0 (2119), isucon[isucon]@isucon1
  SELECT * FROM tags WHERE id = N

Count: 1235  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=1.7 (2119), isucon[isucon]@isucon1
  SELECT * FROM livestream_tags WHERE livestream_id = N

Count: 1269  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=1.0 (1269), isucon[isucon]@isucon1
  SELECT * FROM users WHERE id = N

Count: 1276  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=0.0 (12), isucon[isucon]@isucon1
  SELECT icon_path FROM icons WHERE user_id = N

Count: 1065  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=1.0 (1065), isucon[isucon]@isucon1
  SELECT * FROM livestreams WHERE id = N

Count: 6  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=12.3 (74), isucon[isucon]@isucon1
  SELECT * FROM livestreams WHERE user_id = N

Count: 9  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=109.3 (984), isucon[isucon]@isucon1
  SELECT * FROM livestream_tags WHERE tag_id IN (N) ORDER BY livestream_id DESC

explain

Reading from STDIN ...

# 690ms user time, 20ms system time, 37.00M rss, 51.33M vsz
# Current date: Sat Nov 25 05:57:25 2023
# Hostname: ip-192-168-0-13
# Files: STDIN
# Overall: 8.91k total, 58 unique, 111.35 QPS, 0.01x concurrency _________
# Time range: 2023-11-25T05:56:04 to 2023-11-25T05:57:24
# Attribute          total     min     max     avg     95%  stddev  median
# ============     ======= ======= ======= ======= ======= ======= =======
# Exec time             1s    11us     8ms   124us   247us   412us    52us
# Lock time            4ms       0    34us       0     1us       0       0
# Rows sent         32.01k       0   7.32k    3.68    1.96  115.52    0.99
# Rows examine       1.90M       0  14.00k  223.28  964.41  845.42    0.99
# Query size       363.42k       6     410   41.78   54.21   19.52   38.53

# Profile
# Rank Query ID                       Response time Calls R/Call V/M   Ite
# ==== ============================== ============= ===== ====== ===== ===
#    1 0x38BC86A45F31C6B1EE3246715...  0.3189 28.8%  1273 0.0003  0.00 SELECT themes
#    2 0xA3401CA3ABCC04C3AB221DB8A...  0.1148 10.4%    22 0.0052  0.00 UPDATE reservation_slots
#    3 0x7F9C0C0BA9473953B723EE16C...  0.1108 10.0%    22 0.0050  0.00 SELECT reservation_slots
#    4 0xFBC5564AE716EAE82F20BFB45...  0.1072  9.7%  2119 0.0001  0.00 SELECT tags
# MISC 0xMISC                          0.4553 41.1%  5472 0.0001   0.0 <54 ITEMS>

# Query 1: 181.86 QPS, 0.05x concurrency, ID 0x38BC86A45F31C6B1EE324671506C898A at byte 1941086
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: 2023-11-25T05:56:04 to 2023-11-25T05:56:11
# Attribute    pct   total     min     max     avg     95%  stddev  median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count         14    1273
# Exec time     28   319ms   237us   494us   250us   260us    25us   236us
# Lock time     14   643us       0     2us       0     1us       0     1us
# Rows sent      3   1.24k       1       1       1       1       0       1
# Rows examine  64   1.22M    1000    1002 1001.10  964.41       0  964.41
# Query size    13  49.77k      38      41   40.04   40.45    0.75   38.53
# String:
# Hosts        isucon1
# Users        isucon
# Query_time distribution
#   1us
#  10us
# 100us  ################################################################
#   1ms
#  10ms
# 100ms
#    1s
#  10s+
# Tables
#    SHOW TABLE STATUS LIKE 'themes'\G
#    SHOW CREATE TABLE `themes`\G
# EXPLAIN /*!50100 PARTITIONS*/
SELECT * FROM themes WHERE user_id = 1001\G
# *************************** 1. row ***************************
#            id: 1
#   select_type: SIMPLE
#         table: themes
#    partitions: NULL
#          type: ALL
# possible_keys: NULL
#           key: NULL
#       key_len: NULL
#           ref: NULL
#          rows: 1002
#      filtered: 10.00
#         Extra: Using where

# Query 2: 22 QPS, 0.11x concurrency, ID 0xA3401CA3ABCC04C3AB221DB8AD5CBF26 at byte 516865
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: 2023-11-25T05:56:04 to 2023-11-25T05:56:05
# Attribute    pct   total     min     max     avg     95%  stddev  median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count          0      22
# Exec time     10   115ms     5ms     5ms     5ms     5ms       0     5ms
# Lock time      0    15us       0     1us       0     1us       0     1us
# Rows sent      0       0       0       0       0       0       0       0
# Rows examine   9 188.18k   8.55k   8.55k   8.55k   8.55k       0   8.55k
# Query size     0   2.11k      98      98      98      98       0      98
# String:
# Hosts        isucon1
# Users        isucon
# Query_time distribution
#   1us
#  10us
# 100us
#   1ms  ################################################################
#  10ms
# 100ms
#    1s
#  10s+
# Tables
#    SHOW TABLE STATUS LIKE 'reservation_slots'\G
#    SHOW CREATE TABLE `reservation_slots`\G
UPDATE reservation_slots SET slot = slot - 1 WHERE start_at >= 1711990800 AND end_at <= 1711994400\G
# Converted for EXPLAIN
# EXPLAIN 
select  slot = slot - 1 from reservation_slots where  start_at >= 1711990800 AND end_at <= 1711994400\G

# Query 3: 22 QPS, 0.11x concurrency, ID 0x7F9C0C0BA9473953B723EE16C08655F1 at byte 498692
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: 2023-11-25T05:56:04 to 2023-11-25T05:56:05
# Attribute    pct   total     min     max     avg     95%  stddev  median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count          0      22
# Exec time     10   111ms     5ms     5ms     5ms     5ms    50us     5ms
# Lock time      0    15us       0     1us       0     1us       0     1us
# Rows sent      0      28       1       7    1.27    0.99    1.25    0.99
# Rows examine   9 188.18k   8.55k   8.55k   8.55k   8.55k       0   8.55k
# Query size     0   2.06k      96      96      96      96       0      96
# String:
# Hosts        isucon1
# Users        isucon
# Query_time distribution
#   1us
#  10us
# 100us
#   1ms  ################################################################
#  10ms
# 100ms
#    1s
#  10s+
# Tables
#    SHOW TABLE STATUS LIKE 'reservation_slots'\G
#    SHOW CREATE TABLE `reservation_slots`\G
# EXPLAIN 
SELECT * FROM reservation_slots WHERE start_at >= 1711972800 AND end_at <= 1711976400 FOR UPDATE\G
# *************************** 1. row ***************************
#            id: 1
#   select_type: SIMPLE
#         table: reservation_slots
#    partitions: NULL
#          type: ALL
# possible_keys: NULL
#           key: NULL
#       key_len: NULL
#           ref: NULL
#          rows: 8593
#      filtered: 11.11
#         Extra: Using where

# Query 4: 302.71 QPS, 0.02x concurrency, ID 0xFBC5564AE716EAE82F20BFB45F6C37E7 at byte 306294
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: 2023-11-25T05:56:04 to 2023-11-25T05:56:11
# Attribute    pct   total     min     max     avg     95%  stddev  median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count         23    2119
# Exec time      9   107ms    42us   124us    50us    60us     6us    47us
# Lock time     23     1ms       0     1us       0     1us       0       0
# Rows sent      6   2.07k       1       1       1       1       0       1
# Rows examine   0   2.07k       1       1       1       1       0       1
# Query size    18  66.02k      31      33   31.91   31.70    0.57   31.70
# String:
# Hosts        isucon1
# Users        isucon
# Query_time distribution
#   1us
#  10us  ################################################################
# 100us  #
#   1ms
#  10ms
# 100ms
#    1s
#  10s+
# Tables
#    SHOW TABLE STATUS LIKE 'tags'\G
#    SHOW CREATE TABLE `tags`\G
# EXPLAIN 
SELECT * FROM tags WHERE id = 59\G
# *************************** 1. row ***************************
#            id: 1
#   select_type: SIMPLE
#         table: tags
#    partitions: NULL
#          type: const
# possible_keys: PRIMARY
#           key: PRIMARY
#       key_len: 8
#           ref: const
#          rows: 1
#      filtered: 100.00
#         Extra: NULL

netdata

http://localhost:19993/#menu_services;after=1700891764208;before=1700891844215

pprof

go tool pprof -http=0.0.0.0:1080 http://isucon3/pprof/11250556