SlideShare uma empresa Scribd logo
1 de 27
Baixar para ler offline
MySQL Proxy



    Making MySQL more flexible
          Jan Kneschke
         jan@mysql.com



                 
MySQL Proxy
        proxy­servers forward requests to backends 
    ●



        and can
            transform, handle or block them
        –


        released under the GPL
    ●



            see http://forge.mysql.com/wiki/MySQL_Proxy
        –


        developed as part of the Enterprise Tools since 
    ●



        February 2007
                                   
Design Decisions
        goal is to be transparent to the application layer
    ●




        supports all platforms and languages
    ●




        designed to handle thousands of parallel 
    ●



        connections (c10k)
        uses a embedded scripting language for 
    ●



        customizations


                                
Transparency
        SHOW WARNINGS can be worked around with 
    ●



        Query Injection
        SELECT USER() shows the connected user 
    ●



        (the proxy, not the client) which can be 
        corrected with result­set rewriting
        host auth against the MySQL server
    ●




                              
Latency
        early tests via localhost
    ●




        same script run directly and through the proxy
    ●




        latency per mysql­packet: 0.4ms
    ●




        ping RTT on 1Gbit: 0.1ms
    ●




                                 
Load Balancing
        load balancing distributes the load across 
    ●



        several slaves
        Shortest Queue First is default
    ●



            send new connections to the server with the least 
        –

            number of open connections




                                    
Fail Over
        dead host are detected
    ●




        taking out of load balancing for 2min
    ●




        uses custom load balancers to decide how to 
    ●



        handle a dead host
            hot + standby
        –

            uses load balancing
        –




                                   
Removing SPoF
        one Proxy == Single Point of Failure
    ●




        use external Heartbeat (linuxha.org) or
    ●




        2 LB proxies + 1 Host Selecting Proxy per 
    ●



        application server




                               
Failsafe Load Balancing




                
Flexibility
        proxy embeds LUA 
    ●




        allows analyzing and manipulating packets 
    ●



            Inspection
        –

            Rewriting
        –

            Blocking
        –

            Injection
        –




                               
LUA
        PiL http://lua.org/manual/5.1/
    ●




        embedded, simple, efficient
    ●




        can do OO­like programming
    ●




        has scalars, tables, metatables and anonymous 
    ●



        functions



                                
Query Rewriting
        Macro Packages (ls, cd, who, ...)
    ●




        tagging queries with SQL_CACHE
    ●




        migrating table­names and SQL dialects
    ●




        turn EXPLAIN UPDATE|DELETE  into 
    ●



        equivalent EXPLAIN SELECT



                              
Query Profiling
        SHOW SESSION STATUS around a Query
    ●



    Exec_time: 6749 us
    .. Handler_read_rnd_next = 252
    .. Handler_write = 252
    .. Select_scan = 1




                          
Query Statistics
        Normalize Queries to track query usage
    ●




        Count Table and Index usage
    ●




        Optimize Query Cache Usage by injecting 
    ●



        SQL_CACHE in cachable queries
        see lib/analyze­queries.lua
    ●




                              
Auditing
        Diagnostic Auditing
    ●




        track which user+ip run which query or 
    ●



        accessed which objects when
        assign query­costs
    ●




        log gathered information in a central place
    ●




        see lib/auditing.lua
    ●




                                
Global Transaction ID
        Inject a counter in all transactions
    ●




        Answers questions like
    ●



            which slave is most current
        –

            can I read from this slave, or do I have to read from 
        –

            master
            you name it
        –




                                     
Connection Pooling
        reusing open connections between proxy and 
    ●



        server
        reduces concurrency on the MySQL Server
    ●




        external connection pool for PHP
    ●




                               
Statement Routing
        split the query stream into reading and writing
    ●



            READs go to the slaves
        –

            WRITEs and transactions to the master
        –


        automatic scale­out
    ●




        sharding
    ●




                                      
Tokenizer
        turns a SQL query into a token stream
    ●




        not a full parser, just a tokenizer for speed 
    ●



        reasons
        understands KEYWORDS, /*comments*/, 
    ●



        “strings”, 123 and `literals`
        later we'll add support for SQL modes
    ●




                                 
normalizing Queries

    1:  { TK_SQL_SELECT, select }
    2:  { TK_STAR, * }
    3:  { TK_SQL_FROM, from }
    4:  { TK_LITERAL, t1 }
    5:  { TK_SQL_WHERE, where }
    6:  { TK_LITERAL, id }
    7:  { TK_EQ, = }
    8:  { TK_INTEGER, 1 }
    normalized query: SELECT * FROM `t1` WHERE 
    `id` = ? 



                            
Libraries
        auto­config                      parser
    ●                                ●



            SET GLOBAL ...                   extract tablenames
        –                                –


        balance                          tokenizer
    ●                                ●



            load balancers                   normalize()
        –                                –

                                             cleanup queries
        commands                         –
    ●



            parse MySQL 
        –

            Command Packets
                                  
Internals – LUA scripting
        proxy.* is the namespace
    ●




        proxy.connection.* is the current 
    ●



        connection
        proxy.backends[...] are the backends
    ●




        proxy.global.* is the global table
    ●




        proxy.global.config.* is used for the 
    ●



        config
                             
Internals ­ Scope
        Each connection has its own script scope
    ●




        proxy.global.* to share data between 
    ●



        connections
        use local to make variables local to the 
    ●



        function
        use package.seeall() to export functions 
    ●



        from modules
                               
Internals ­ Threading
        the global scope and threading don't play nice 
    ●



        by default
        http://www.cs.princeton.edu/~diego/professional/lua
    ●




        patches lua to apply mutexes around variable 
    ●



        access




                               
Internals – Script Cache
        0.6.0 we reload the script on each connection 
    ●



        start
        adding a script cache with mtime check
    ●




        lua_pushvalue(L, ­1) does the trick
    ●




                               
Roadmap
        to be released 0.6.0
    ●



            tokenizer
        –

            read­write splitting
        –

            Query Statistics
        –


        later
    ●



            parallel Queries
        –

            proxy initiates connections
        –

                                    
LUA ­ Gotchas
        only false and nil are !true, 0 is true
    ●




        to say “not equal” you use ~=
    ●




        there are no shortcuts
    ●



            no a++, no a *= 4, ...
        –

            no a > b ? a : b (there is “(a > b) and a or b)
        –




                                      

Mais conteúdo relacionado

Mais procurados

Upgrading oracle db 11.2.0.1 to 11.2.0.3
Upgrading oracle db 11.2.0.1 to 11.2.0.3Upgrading oracle db 11.2.0.1 to 11.2.0.3
Upgrading oracle db 11.2.0.1 to 11.2.0.3Ravi Kumar Lanke
 
HandsOn ProxySQL Tutorial - PLSC18
HandsOn ProxySQL Tutorial - PLSC18HandsOn ProxySQL Tutorial - PLSC18
HandsOn ProxySQL Tutorial - PLSC18Derek Downey
 
Percona live 2021 Practical Database Automation with Ansible
Percona live 2021 Practical Database Automation with Ansible Percona live 2021 Practical Database Automation with Ansible
Percona live 2021 Practical Database Automation with Ansible Derek Downey
 
Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database DeploymentsMike Willbanks
 
Fortify aws aurora_proxy
Fortify aws aurora_proxyFortify aws aurora_proxy
Fortify aws aurora_proxyMarco Tusa
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012Roland Bouman
 
Introduction to Spring Cloud Kubernetes (July 4th, 2019)
Introduction to Spring Cloud Kubernetes (July 4th, 2019)Introduction to Spring Cloud Kubernetes (July 4th, 2019)
Introduction to Spring Cloud Kubernetes (July 4th, 2019)Alexandre Roman
 
OpenWorld 2014 - Schema Management: versioning and automation with Puppet and...
OpenWorld 2014 - Schema Management: versioning and automation with Puppet and...OpenWorld 2014 - Schema Management: versioning and automation with Puppet and...
OpenWorld 2014 - Schema Management: versioning and automation with Puppet and...Frederic Descamps
 
SQL Server Exploitation, Escalation, Pilfering - AppSec USA 2012
SQL Server Exploitation, Escalation, Pilfering - AppSec USA 2012SQL Server Exploitation, Escalation, Pilfering - AppSec USA 2012
SQL Server Exploitation, Escalation, Pilfering - AppSec USA 2012Scott Sutherland
 
Habits of Effective Sqoop Users
Habits of Effective Sqoop UsersHabits of Effective Sqoop Users
Habits of Effective Sqoop UsersKathleen Ting
 
Performance Tuning Oracle Weblogic Server 12c
Performance Tuning Oracle Weblogic Server 12cPerformance Tuning Oracle Weblogic Server 12c
Performance Tuning Oracle Weblogic Server 12cAjith Narayanan
 
New Stuff in the Oracle PL/SQL Language
New Stuff in the Oracle PL/SQL LanguageNew Stuff in the Oracle PL/SQL Language
New Stuff in the Oracle PL/SQL LanguageSteven Feuerstein
 
Apache Kafka® Security Overview
Apache Kafka® Security OverviewApache Kafka® Security Overview
Apache Kafka® Security Overviewconfluent
 
2016 aRcTicCON - Hacking SQL Server on Scale with PowerShell (Slide Updates)
2016 aRcTicCON - Hacking SQL Server on Scale with PowerShell (Slide Updates)2016 aRcTicCON - Hacking SQL Server on Scale with PowerShell (Slide Updates)
2016 aRcTicCON - Hacking SQL Server on Scale with PowerShell (Slide Updates)Scott Sutherland
 
2017 Q1 Arcticcon - Meet Up - Adventures in Adversarial Emulation
2017 Q1 Arcticcon - Meet Up - Adventures in Adversarial Emulation2017 Q1 Arcticcon - Meet Up - Adventures in Adversarial Emulation
2017 Q1 Arcticcon - Meet Up - Adventures in Adversarial EmulationScott Sutherland
 

Mais procurados (18)

Upgrading oracle db 11.2.0.1 to 11.2.0.3
Upgrading oracle db 11.2.0.1 to 11.2.0.3Upgrading oracle db 11.2.0.1 to 11.2.0.3
Upgrading oracle db 11.2.0.1 to 11.2.0.3
 
HandsOn ProxySQL Tutorial - PLSC18
HandsOn ProxySQL Tutorial - PLSC18HandsOn ProxySQL Tutorial - PLSC18
HandsOn ProxySQL Tutorial - PLSC18
 
Percona live 2021 Practical Database Automation with Ansible
Percona live 2021 Practical Database Automation with Ansible Percona live 2021 Practical Database Automation with Ansible
Percona live 2021 Practical Database Automation with Ansible
 
PPT
PPTPPT
PPT
 
Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database Deployments
 
Fortify aws aurora_proxy
Fortify aws aurora_proxyFortify aws aurora_proxy
Fortify aws aurora_proxy
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Spring Mvc Rest
Spring Mvc RestSpring Mvc Rest
Spring Mvc Rest
 
Introduction to Spring Cloud Kubernetes (July 4th, 2019)
Introduction to Spring Cloud Kubernetes (July 4th, 2019)Introduction to Spring Cloud Kubernetes (July 4th, 2019)
Introduction to Spring Cloud Kubernetes (July 4th, 2019)
 
OpenWorld 2014 - Schema Management: versioning and automation with Puppet and...
OpenWorld 2014 - Schema Management: versioning and automation with Puppet and...OpenWorld 2014 - Schema Management: versioning and automation with Puppet and...
OpenWorld 2014 - Schema Management: versioning and automation with Puppet and...
 
SQL Server Exploitation, Escalation, Pilfering - AppSec USA 2012
SQL Server Exploitation, Escalation, Pilfering - AppSec USA 2012SQL Server Exploitation, Escalation, Pilfering - AppSec USA 2012
SQL Server Exploitation, Escalation, Pilfering - AppSec USA 2012
 
Apache servicemix1
Apache servicemix1Apache servicemix1
Apache servicemix1
 
Habits of Effective Sqoop Users
Habits of Effective Sqoop UsersHabits of Effective Sqoop Users
Habits of Effective Sqoop Users
 
Performance Tuning Oracle Weblogic Server 12c
Performance Tuning Oracle Weblogic Server 12cPerformance Tuning Oracle Weblogic Server 12c
Performance Tuning Oracle Weblogic Server 12c
 
New Stuff in the Oracle PL/SQL Language
New Stuff in the Oracle PL/SQL LanguageNew Stuff in the Oracle PL/SQL Language
New Stuff in the Oracle PL/SQL Language
 
Apache Kafka® Security Overview
Apache Kafka® Security OverviewApache Kafka® Security Overview
Apache Kafka® Security Overview
 
2016 aRcTicCON - Hacking SQL Server on Scale with PowerShell (Slide Updates)
2016 aRcTicCON - Hacking SQL Server on Scale with PowerShell (Slide Updates)2016 aRcTicCON - Hacking SQL Server on Scale with PowerShell (Slide Updates)
2016 aRcTicCON - Hacking SQL Server on Scale with PowerShell (Slide Updates)
 
2017 Q1 Arcticcon - Meet Up - Adventures in Adversarial Emulation
2017 Q1 Arcticcon - Meet Up - Adventures in Adversarial Emulation2017 Q1 Arcticcon - Meet Up - Adventures in Adversarial Emulation
2017 Q1 Arcticcon - Meet Up - Adventures in Adversarial Emulation
 

Semelhante a MySQL Proxy

Galera Multi Master Synchronous My S Q L Replication Clusters
Galera  Multi Master  Synchronous  My S Q L  Replication  ClustersGalera  Multi Master  Synchronous  My S Q L  Replication  Clusters
Galera Multi Master Synchronous My S Q L Replication ClustersPerconaPerformance
 
Systems Automation with Puppet
Systems Automation with PuppetSystems Automation with Puppet
Systems Automation with Puppetelliando dias
 
My Sql Proxy
My Sql ProxyMy Sql Proxy
My Sql ProxyLiu Lizhi
 
Make Your Life Easier With Maatkit
Make Your Life Easier With MaatkitMake Your Life Easier With Maatkit
Make Your Life Easier With MaatkitMySQLConference
 
Deploy Rails Application by Capistrano
Deploy Rails Application by CapistranoDeploy Rails Application by Capistrano
Deploy Rails Application by CapistranoTasawr Interactive
 
Gmr Highload Presentation Revised
Gmr Highload Presentation RevisedGmr Highload Presentation Revised
Gmr Highload Presentation RevisedOntico
 
Gmr Highload Presentation
Gmr Highload PresentationGmr Highload Presentation
Gmr Highload PresentationOntico
 
My sql monitoring cu沙龙
My sql monitoring cu沙龙My sql monitoring cu沙龙
My sql monitoring cu沙龙colderboy17
 
YAPC2007 Remote System Monitoring (w. Notes)
YAPC2007 Remote System Monitoring (w. Notes)YAPC2007 Remote System Monitoring (w. Notes)
YAPC2007 Remote System Monitoring (w. Notes)rgiersig
 
Text indexing and search libraries for PHP - Zoë Slattery - Barcelona PHP Con...
Text indexing and search libraries for PHP - Zoë Slattery - Barcelona PHP Con...Text indexing and search libraries for PHP - Zoë Slattery - Barcelona PHP Con...
Text indexing and search libraries for PHP - Zoë Slattery - Barcelona PHP Con...phpbarcelona
 
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...Timofey Turenko
 
High Availability with MySQL
High Availability with MySQLHigh Availability with MySQL
High Availability with MySQLThava Alagu
 
Kafka Connect - debezium
Kafka Connect - debeziumKafka Connect - debezium
Kafka Connect - debeziumKasun Don
 
Smart Client Development
Smart Client DevelopmentSmart Client Development
Smart Client DevelopmentTamir Khason
 

Semelhante a MySQL Proxy (20)

Galera Multi Master Synchronous My S Q L Replication Clusters
Galera  Multi Master  Synchronous  My S Q L  Replication  ClustersGalera  Multi Master  Synchronous  My S Q L  Replication  Clusters
Galera Multi Master Synchronous My S Q L Replication Clusters
 
MySQL Proxy tutorial
MySQL Proxy tutorialMySQL Proxy tutorial
MySQL Proxy tutorial
 
Os Wilhelm
Os WilhelmOs Wilhelm
Os Wilhelm
 
Systems Automation with Puppet
Systems Automation with PuppetSystems Automation with Puppet
Systems Automation with Puppet
 
Capistrano
CapistranoCapistrano
Capistrano
 
My Sql Proxy
My Sql ProxyMy Sql Proxy
My Sql Proxy
 
Make Your Life Easier With Maatkit
Make Your Life Easier With MaatkitMake Your Life Easier With Maatkit
Make Your Life Easier With Maatkit
 
Deploy Rails Application by Capistrano
Deploy Rails Application by CapistranoDeploy Rails Application by Capistrano
Deploy Rails Application by Capistrano
 
Gmr Highload Presentation Revised
Gmr Highload Presentation RevisedGmr Highload Presentation Revised
Gmr Highload Presentation Revised
 
Gmr Highload Presentation
Gmr Highload PresentationGmr Highload Presentation
Gmr Highload Presentation
 
My sql monitoring cu沙龙
My sql monitoring cu沙龙My sql monitoring cu沙龙
My sql monitoring cu沙龙
 
YAPC2007 Remote System Monitoring (w. Notes)
YAPC2007 Remote System Monitoring (w. Notes)YAPC2007 Remote System Monitoring (w. Notes)
YAPC2007 Remote System Monitoring (w. Notes)
 
Download It
Download ItDownload It
Download It
 
Text indexing and search libraries for PHP - Zoë Slattery - Barcelona PHP Con...
Text indexing and search libraries for PHP - Zoë Slattery - Barcelona PHP Con...Text indexing and search libraries for PHP - Zoë Slattery - Barcelona PHP Con...
Text indexing and search libraries for PHP - Zoë Slattery - Barcelona PHP Con...
 
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
DB proxy server test: run tests on tens of virtual machines with Jenkins, Vag...
 
Capistrano2
Capistrano2Capistrano2
Capistrano2
 
High Availability with MySQL
High Availability with MySQLHigh Availability with MySQL
High Availability with MySQL
 
Kafka Connect - debezium
Kafka Connect - debeziumKafka Connect - debezium
Kafka Connect - debezium
 
Smart Client Development
Smart Client DevelopmentSmart Client Development
Smart Client Development
 
Conflict Resolution In Kai
Conflict Resolution In KaiConflict Resolution In Kai
Conflict Resolution In Kai
 

Último

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 

Último (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 

MySQL Proxy

  • 1. MySQL Proxy Making MySQL more flexible Jan Kneschke jan@mysql.com    
  • 2. MySQL Proxy proxy­servers forward requests to backends  ● and can transform, handle or block them – released under the GPL ● see http://forge.mysql.com/wiki/MySQL_Proxy – developed as part of the Enterprise Tools since  ● February 2007    
  • 3. Design Decisions goal is to be transparent to the application layer ● supports all platforms and languages ● designed to handle thousands of parallel  ● connections (c10k) uses a embedded scripting language for  ● customizations    
  • 4. Transparency SHOW WARNINGS can be worked around with  ● Query Injection SELECT USER() shows the connected user  ● (the proxy, not the client) which can be  corrected with result­set rewriting host auth against the MySQL server ●    
  • 5. Latency early tests via localhost ● same script run directly and through the proxy ● latency per mysql­packet: 0.4ms ● ping RTT on 1Gbit: 0.1ms ●    
  • 6. Load Balancing load balancing distributes the load across  ● several slaves Shortest Queue First is default ● send new connections to the server with the least  – number of open connections    
  • 7. Fail Over dead host are detected ● taking out of load balancing for 2min ● uses custom load balancers to decide how to  ● handle a dead host hot + standby – uses load balancing –    
  • 8. Removing SPoF one Proxy == Single Point of Failure ● use external Heartbeat (linuxha.org) or ● 2 LB proxies + 1 Host Selecting Proxy per  ● application server    
  • 10. Flexibility proxy embeds LUA  ● allows analyzing and manipulating packets  ● Inspection – Rewriting – Blocking – Injection –    
  • 11. LUA PiL http://lua.org/manual/5.1/ ● embedded, simple, efficient ● can do OO­like programming ● has scalars, tables, metatables and anonymous  ● functions    
  • 12. Query Rewriting Macro Packages (ls, cd, who, ...) ● tagging queries with SQL_CACHE ● migrating table­names and SQL dialects ● turn EXPLAIN UPDATE|DELETE  into  ● equivalent EXPLAIN SELECT    
  • 13. Query Profiling SHOW SESSION STATUS around a Query ● Exec_time: 6749 us .. Handler_read_rnd_next = 252 .. Handler_write = 252 .. Select_scan = 1    
  • 14. Query Statistics Normalize Queries to track query usage ● Count Table and Index usage ● Optimize Query Cache Usage by injecting  ● SQL_CACHE in cachable queries see lib/analyze­queries.lua ●    
  • 15. Auditing Diagnostic Auditing ● track which user+ip run which query or  ● accessed which objects when assign query­costs ● log gathered information in a central place ● see lib/auditing.lua ●    
  • 16. Global Transaction ID Inject a counter in all transactions ● Answers questions like ● which slave is most current – can I read from this slave, or do I have to read from  – master you name it –    
  • 17. Connection Pooling reusing open connections between proxy and  ● server reduces concurrency on the MySQL Server ● external connection pool for PHP ●    
  • 18. Statement Routing split the query stream into reading and writing ● READs go to the slaves – WRITEs and transactions to the master – automatic scale­out ● sharding ●    
  • 19. Tokenizer turns a SQL query into a token stream ● not a full parser, just a tokenizer for speed  ● reasons understands KEYWORDS, /*comments*/,  ● “strings”, 123 and `literals` later we'll add support for SQL modes ●    
  • 20. normalizing Queries 1:  { TK_SQL_SELECT, select } 2:  { TK_STAR, * } 3:  { TK_SQL_FROM, from } 4:  { TK_LITERAL, t1 } 5:  { TK_SQL_WHERE, where } 6:  { TK_LITERAL, id } 7:  { TK_EQ, = } 8:  { TK_INTEGER, 1 } normalized query: SELECT * FROM `t1` WHERE  `id` = ?     
  • 21. Libraries auto­config parser ● ● SET GLOBAL ...  extract tablenames – – balance tokenizer ● ● load balancers normalize() – – cleanup queries commands – ● parse MySQL  – Command Packets    
  • 22. Internals – LUA scripting proxy.* is the namespace ● proxy.connection.* is the current  ● connection proxy.backends[...] are the backends ● proxy.global.* is the global table ● proxy.global.config.* is used for the  ● config    
  • 23. Internals ­ Scope Each connection has its own script scope ● proxy.global.* to share data between  ● connections use local to make variables local to the  ● function use package.seeall() to export functions  ● from modules    
  • 24. Internals ­ Threading the global scope and threading don't play nice  ● by default http://www.cs.princeton.edu/~diego/professional/lua ● patches lua to apply mutexes around variable  ● access    
  • 25. Internals – Script Cache 0.6.0 we reload the script on each connection  ● start adding a script cache with mtime check ● lua_pushvalue(L, ­1) does the trick ●    
  • 26. Roadmap to be released 0.6.0 ● tokenizer – read­write splitting – Query Statistics – later ● parallel Queries – proxy initiates connections –    
  • 27. LUA ­ Gotchas only false and nil are !true, 0 is true ● to say “not equal” you use ~= ● there are no shortcuts ● no a++, no a *= 4, ... – no a > b ? a : b (there is “(a > b) and a or b) –