17
MySQL Benchmark Techniques June 27, 2012 Zhang Lu Sr. Operations Architect [email protected]

MySQL Benchmark Techniques June 27, 2012 Zhang Lu Sr. Operations Architect zhang.lu@teamaol

  • Upload
    teige

  • View
    43

  • Download
    0

Embed Size (px)

DESCRIPTION

MySQL Benchmark Techniques June 27, 2012 Zhang Lu Sr. Operations Architect [email protected]. Million dollar questions. Why benchmarking is important? - PowerPoint PPT Presentation

Citation preview

Slide 1

MySQL Benchmark Techniques

June 27, 2012Zhang Lu Sr. Operations Architect

[email protected] dollar questionsWhy benchmarking is important?Benchmarking is the study of a company or organization that excels in all aspects of its achievements, then using the data that is collected to improve the performance of their own companyWhat is performance?Performance is your customers happiness AOL PowerPoint Template | ConfidentialBenchmark typesPre-productionresearchPost-production New hardware rolloutNew software (server) rolloutSchema changes (tuning)Configuration changes (tuning)

AOL PowerPoint Template | ConfidentialThe stepsClone production databaseCatch production trafficReplay (real time or offline)Comparison and draw conclusion

AOL PowerPoint Template | ConfidentialCatch production traffic tcpdumpUse tcpdump to capture TCP packets to/from MySQL server portpt-query-digest to parse tcpdump outputProsNo interruption to applicationEasy to get startedConsIt takes time to parse the fileNot easy to replay in real timeNo information of current DB name at the time of request AOL PowerPoint Template | ConfidentialCatch production traffic MySQL ProxySetup mysqlproxy to use production DB as backendModify lua script to save incoming requests along with request time (offset), response time, etc.Bounce application to use mysqlproxy port instead of MySQL portProsFlexibleReal time replay is possibleConsAdditional process needs to be setup (mysqlproxy)Requires some understanding of LUA language AOL PowerPoint Template | ConfidentialReplayTrue production replaySame interval between establishing new connectionsSame interval between each requestOnly difference is the response time of each requestStress testNo wait between each requestAdjust interval between new connectionsReplay each set of files multiple times with overlaps

AOL PowerPoint Template | ConfidentialUsing tcpdump and pt-query-digesttcpdump -s 65535 -x -nn -q -tttt -i any -c 9000000 port 3306Packet size 65535 (-s)Print each packet in HEX (-x)Do not convert protocol and port to name (-nn)Quiet less protocol information (-q)Print timestamp in default format (-tttt)Any interface (NIC) (-i)Capture 9000000 packets and exit (-c)Only capture traffic in/out port 3306pt-query-digest --type=tcpdump --watch-server=10.10.10.123:3306 --print --no-reportMust specify IP:PORT if your DB is not running on 3306Use nc to stream data to another host, either save for later use or just pipe to pt-query-digest

AOL PowerPoint Template | ConfidentialUsing tcpdump and pt-query-digest - contBefore replaying, need to split the output from pt-query-digestSplit query into different files based on client IP and portReformat meta data in the form that the replay script can understand

AOL PowerPoint Template | Confidential# Time: 120427 11:07:20.908902# Client: 172.19.160.8:48366# Thread_id: 4294967305# Query time: 0.000154 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0SELECT * FROM my_table;# Time: 120427 11:07:20.910313# Client: 172.19.160.8:48366# Thread_id: 4294967305# Query_time: 0.000454 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0SELECT * FROM my_table2;Using mysqlproxy - setupConfiguration file AOL PowerPoint Template | Confidential[mysql-proxy]log-file = /var/log/mysql-proxy.loglog-level = messageproxy-address=:4040proxy-backend-addresses=dbslab-mtc02.ops.aol.com:3406admin-address = 127.0.0.1:4041admin-username = prootadmin-password = padminadmin-lua-script = /var/lib/mysql-proxy/lua/admin.luakeepalive = trueproxy-lua-script=/var/lib/mysql-proxy/lua/proxy/myproxy.luaUsing mysqlproxy lua script Loaded for each connection requestCan be updated on the flyExternal modules can be loadedMySQL DB requests is sequential per connectionIt is possible to send the query to another connection other than production, but that means the client response time is doubledManipulate incoming requests before send to the serverManipulate result set before send back to the client

AOL PowerPoint Template | ConfidentialUsing mysqlproxy lua script functionsread_auth_result()

AOL PowerPoint Template | Confidentialfunction read_auth_result(auth) local time = os.time() local state = auth.packet:byte() con_time = time if state == proxy.MYSQLD_PACKET_OK then myvars.file = proxy.global.file_base .. "." .. time .. "." .. proxy.connection.server['thread_id']; myvars.fh = io.open(myvars.file, "a"); if proxy.connection.client.default_db ~= '' then query_id = query_id + 1 myvars.fh:write("### Start Time Offset=0 Query Time=0 Response Time=0 Query ID=" .. query_id .. " Username=" .. proxy.connection.server['username'] .. "\nUSE " .. proxy.connection.client.default_db .. "\n### End\n") myvars.fh:flush() end endendUsing mysqlproxy lua script functions (contd)read_query() AOL PowerPoint Template | Confidentialfunction read_query( packet ) query = packet:sub(2) q_time = os.time() - con_time myvars.query= query if (string.byte(packet) == proxy.COM_QUIT) then proxy.global.type = proxy.MYSQLD_PACKET_OK myvars.fh:write("### Disconnected\n") myvars.fh:close() return proxy.PROXY_SEND_RESULT elseif string.byte(packet) == proxy.COM_INIT_DB then query_id = query_id + 1 myvars.fh:write("### Start Time Offset=0 Query Time=0 Response Time=0 Query ID=" .. query_id .. " Username=" .. proxy.connection.server['username'] .. "\nUSE " .. query .. "\n### End\n") return elseif string.byte(packet) == proxy.COM_QUERY then proxy.queries:append(1, string.char(proxy.COM_QUERY) .. query, { resultset_is_needed = true } ) return proxy.PROXY_SEND_QUERY endend Using mysqlproxy lua script functions (contd)read_query_result() AOL PowerPoint Template | Confidentialfunction read_query_result(inj) -- filter out those SHOW commands -- both inj.query_time and inj.response_time are in micro seconds, print using milli seconds if string.find(string.upper(myvars.query), '^SHOW ') then return end query_id = query_id + 1 header = "### Start Time Offset=" .. q_time .. " Query Time=" .. (inj.query_time / 1000) .. " Response Time=" .. (inj.response_time / 1000) .. " Query ID=" .. query_id .. "\n" myvars.fh:write(header) myvars.fh:write(myvars.query .. "\n### End\n") myvars.fh:flush()endReferencehttp://dev.mysql.com/doc/refman/5.5/en/mysql-proxy-scripting-structures.html ReplayUsing any language that can talk to MySQL serverMain thread watches the lua generated filesCollect all files in the log directory and sort by created timestampWhen the wait time is up (delta between the timestamps), which is optional, an new connection is establishedEach file is processed over one connectionReplay thread Sends the requests in file to the server based on the interval between each captured queries (optional)Record query ID along with response time for analysis

AOL PowerPoint Template | ConfidentialCompare Overall DB time AOL PowerPoint Template | ConfidentialCompare Update DB time AOL PowerPoint Template | Confidential