saza-ku / isucon13

0 stars 0 forks source link

11250639 #61

Open saza-ku opened 8 months ago

saza-ku commented 8 months ago

isucon1

alp

+-------+--------+------------------------------------------+-------+-------+-------+-------+-------+
| COUNT | METHOD |                   URI                    |  MIN  |  MAX  |  SUM  |  AVG  |  P99  |
+-------+--------+------------------------------------------+-------+-------+-------+-------+-------+
| 12    | GET    | /api/livestream/.+                       | 0.004 | 0.268 | 2.224 | 0.185 | 0.268 |
| 22    | POST   | /api/livestream/.+                       | 0.012 | 0.020 | 0.328 | 0.015 | 0.020 |
| 2     | POST   | /api/register                            | 0.036 | 0.036 | 0.072 | 0.036 | 0.036 |
| 2     | GET    | /api/user/.+/statistics                  | 0.028 | 0.028 | 0.056 | 0.028 | 0.028 |
| 2     | GET    | /api/livestream/.+/statistics            | 0.024 | 0.028 | 0.052 | 0.026 | 0.028 |
| 2     | POST   | /api/livestream/.+/livecomment/.+/report | 0.008 | 0.008 | 0.016 | 0.008 | 0.008 |
| 3     | POST   | /api/livestream/.+/reaction              | 0.004 | 0.008 | 0.016 | 0.005 | 0.008 |
| 1     | GET    | /api/livestream                          | 0.016 | 0.016 | 0.016 | 0.016 | 0.016 |
| 2     | POST   | /api/livestream/.+/livecomment           | 0.004 | 0.008 | 0.012 | 0.006 | 0.008 |
| 2     | POST   | /api/livestream/.+/enter                 | 0.004 | 0.004 | 0.004 | 0.002 | 0.004 |
| 3     | GET    | /api/tag                                 | 0.000 | 0.004 | 0.004 | 0.001 | 0.004 |
| 5     | POST   | /api/login                               | 0.004 | 0.004 | 0.004 | 0.001 | 0.004 |
| 4     | GET    | /api/user/.+                             | 0.000 | 0.004 | 0.004 | 0.001 | 0.004 |
| 1     | GET    | /api/user/.+/theme                       | 0.004 | 0.004 | 0.004 | 0.004 | 0.004 |
| 1     | GET    | /api/user/.+/icon                        | 0.004 | 0.004 | 0.004 | 0.004 | 0.004 |
| 1     | POST   | /api/icon                                | 0.004 | 0.004 | 0.004 | 0.004 | 0.004 |
| 1     | GET    | /api/payment                             | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 |
| 1     | DELETE | /api/livestream/.+/exit                  | 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=1700894379803;before=1700894455842

pprof

go tool pprof -http=0.0.0.0:1080 http://isucon1/pprof/11250639
saza-ku commented 8 months ago

isucon2

alp

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

slow query

Count: 61  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=0.8 (50), 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: 58  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=0.5 (30), 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: 62  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: 197  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=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=1.0 (2), isudns[isudns]@isucon1
  select id,name,master,last_check,notified_serial,type,options,catalog,account from domains where name='S'

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

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

explain

Reading from STDIN ...

# 170ms user time, 10ms system time, 36.12M rss, 50.75M vsz
# Current date: Sat Nov 25 06:41:00 2023
# Hostname: ip-192-168-0-12
# Files: STDIN
# Overall: 403 total, 20 unique, 4.98 QPS, 0.00x concurrency _____________
# Time range: 2023-11-25T06:39:39 to 2023-11-25T06:41:00
# Attribute          total     min     max     avg     95%  stddev  median
# ============     ======= ======= ======= ======= ======= ======= =======
# Exec time          115ms     1us     4ms   284us   725us   413us    69us
# Lock time          202us       0     3us       0     1us       0       0
# Rows sent             88       0       1    0.22    0.99    0.41       0
# Rows examine     156.31k       0   1.25k  397.16   1.20k  569.34       0
# Query size        30.40k       5     195   77.24  136.99   47.63   31.70

# Profile
# Rank Query ID                        Response time Calls R/Call V/M   It
# ==== =============================== ============= ===== ====== ===== ==
#    1 0x42EF7D7D98FBCC9723BF896EBF...  0.0483 42.1%    61 0.0008  0.00 SELECT records
#    2 0x3D83BC87F3B3A00D571FFC8104...  0.0443 38.6%    58 0.0008  0.00 SELECT records
#    3 0x22279D81D51006139E0C76405B...  0.0060  5.2%    62 0.0001  0.00 SELECT domains domainmetadata
#    4 0xE77769C62EF669AA7DD5F6760F...  0.0048  4.2%     2 0.0024  0.00 SHOW VARIABLES
# MISC 0xMISC                           0.0113  9.9%   220 0.0001   0.0 <16 ITEMS>

# Query 1: 20.33 QPS, 0.02x concurrency, ID 0x42EF7D7D98FBCC9723BF896EBFC51D24 at byte 2987
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: 2023-11-25T06:39:39 to 2023-11-25T06:39:42
# Attribute    pct   total     min     max     avg     95%  stddev  median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count         15      61
# Exec time     42    48ms   699us     2ms   792us   725us   269us   690us
# Lock time     25    52us       0     2us       0     1us       0     1us
# Rows sent     56      50       0       1    0.82    0.99    0.38    0.99
# Rows examine  48  76.27k   1.25k   1.25k   1.25k   1.20k       0   1.20k
# Query size    26   8.02k     129     144  134.67  143.84    4.73  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='predict.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='predict.u.isucon.dev' and domain_id=4"] at /usr/bin/pt-query-digest line 7796.

# Query 2: 19.33 QPS, 0.01x concurrency, ID 0x3D83BC87F3B3A00D571FFC8104A6E50C at byte 4698
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: 2023-11-25T06:39:39 to 2023-11-25T06:39:42
# Attribute    pct   total     min     max     avg     95%  stddev  median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count         14      58
# Exec time     38    44ms   653us     2ms   764us     1ms   216us   657us
# Lock time     31    64us       0     3us     1us     1us       0     1us
# Rows sent     34      30       0       1    0.52    0.99    0.50    0.99
# Rows examine  46  72.52k   1.25k   1.25k   1.25k   1.20k       0   1.20k
# Query size    24   7.35k     126     143  129.84  136.99    4.56  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: 20.67 QPS, 0.00x concurrency, ID 0x22279D81D51006139E0C76405B54C261 at byte 2432
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: 2023-11-25T06:39:39 to 2023-11-25T06:39:42
# Attribute    pct   total     min     max     avg     95%  stddev  median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count         15      62
# Exec time      5     6ms    72us   225us    96us   125us    26us    84us
# Lock time     35    72us     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    22   6.90k     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 111929
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: all events occurred at 2023-11-25T06:41:00
# Attribute    pct   total     min     max     avg     95%  stddev  median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count          0       2
# Exec time      4     5ms   984us     4ms     2ms     4ms     2ms     2ms
# Lock time      1     3us     1us     2us     1us     2us       0     1us
# Rows sent      2       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=1700894379827;before=1700894459835

pprof

go tool pprof -http=0.0.0.0:1080 http://isucon2/pprof/11250639
saza-ku commented 8 months ago

isucon3

alp

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

slow query

Count: 1144  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=1.0 (1144), 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: 1856  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=1.0 (1856), isucon[isucon]@isucon1
  SELECT * FROM tags WHERE id = N

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

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

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

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

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

Count: 2  Time=0.01s (0s)  Lock=0.00s (0s)  Rows=7496.0 (14992), isucon[isucon]@isucon1
  SELECT * FROM livestreams

explain

Reading from STDIN ...

# 590ms user time, 10ms system time, 36.75M rss, 51.27M vsz
# Current date: Sat Nov 25 06:41:00 2023
# Hostname: ip-192-168-0-13
# Files: STDIN
# Overall: 7.31k total, 52 unique, 90.27 QPS, 0.01x concurrency __________
# Time range: 2023-11-25T06:39:39 to 2023-11-25T06:41:00
# Attribute          total     min     max     avg     95%  stddev  median
# ============     ======= ======= ======= ======= ======= ======= =======
# Exec time          973ms    13us     9ms   133us   247us   454us    54us
# Lock time            4ms       0    15us       0     1us       0     1us
# Rows sent         31.06k       0   7.32k    4.35    1.96  127.50    0.99
# Rows examine       1.65M       0  10.87k  236.26  964.41  863.50    0.99
# Query size       298.12k       6     413   41.75   54.21   20.46   38.53

# Profile
# Rank Query ID                       Response time Calls R/Call V/M   Ite
# ==== ============================== ============= ===== ====== ===== ===
#    1 0x38BC86A45F31C6B1EE3246715...  0.2837 29.2%  1144 0.0002  0.00 SELECT themes
#    2 0xA3401CA3ABCC04C3AB221DB8A...  0.1190 12.2%    22 0.0054  0.00 UPDATE reservation_slots
#    3 0x7F9C0C0BA9473953B723EE16C...  0.1146 11.8%    22 0.0052  0.00 SELECT reservation_slots
#    4 0xFBC5564AE716EAE82F20BFB45...  0.0958  9.9%  1856 0.0001  0.00 SELECT tags
# MISC 0xMISC                          0.3594 37.0%  4268 0.0001   0.0 <48 ITEMS>

# Query 1: 228.80 QPS, 0.06x concurrency, ID 0x38BC86A45F31C6B1EE324671506C898A at byte 18750
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: 2023-11-25T06:39:39 to 2023-11-25T06:39:44
# Attribute    pct   total     min     max     avg     95%  stddev  median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count         15    1144
# Exec time     29   284ms   237us   588us   247us   260us    24us   236us
# Lock time     15   676us       0    14us       0     1us       0     1us
# Rows sent      3   1.12k       1       1       1       1       0       1
# Rows examine  66   1.09M    1000    1002 1001.00  964.41    0.00  964.41
# Query size    14  44.62k      38      41   39.94   40.45    0.53   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 = 22\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: 11 QPS, 0.06x concurrency, ID 0xA3401CA3ABCC04C3AB221DB8AD5CBF26 at byte 501647
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: 2023-11-25T06:39:39 to 2023-11-25T06:39:41
# Attribute    pct   total     min     max     avg     95%  stddev  median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count          0      22
# Exec time     12   119ms     5ms     6ms     5ms     6ms   259us     5ms
# Lock time      0    16us       0     1us       0     1us       0     1us
# Rows sent      0       0       0       0       0       0       0       0
# Rows examine  11 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: 11 QPS, 0.06x concurrency, ID 0x7F9C0C0BA9473953B723EE16C08655F1 at byte 498022
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: 2023-11-25T06:39:39 to 2023-11-25T06:39:41
# Attribute    pct   total     min     max     avg     95%  stddev  median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count          0      22
# Exec time     11   115ms     5ms     6ms     5ms     5ms   241us     5ms
# Lock time      0    17us       0     1us       0     1us       0     1us
# Rows sent      0      28       1       7    1.27    0.99    1.25    0.99
# Rows examine  11 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 >= 1711987200 AND end_at <= 1711990800 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: 928 QPS, 0.05x concurrency, ID 0xFBC5564AE716EAE82F20BFB45F6C37E7 at byte 1488942
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: 2023-11-25T06:39:40 to 2023-11-25T06:39:42
# Attribute    pct   total     min     max     avg     95%  stddev  median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count         25    1856
# Exec time      9    96ms    44us   105us    51us    60us     5us    49us
# Lock time     25     1ms       0    15us       0     1us       0     1us
# Rows sent      5   1.81k       1       1       1       1       0       1
# Rows examine   0   1.81k       1       1       1       1       0       1
# Query size    19  57.73k      31      33   31.85   31.70    0.64   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 = 31\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=1700894379817;before=1700894459824

pprof

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