SlideShare uma empresa Scribd logo
1 de 38
Baixar para ler offline
HANDLERSOCKET
A NOSQL APPROACH TO MYSQL
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
ABOUT ME
Lukasz Barulski
• backend dev AKA IAmDoingEverythingExceptFrontend dev
• been with DocPlanner since dinosaurs
• kicks butts in MK X
/lbarulski /in/lukaszbarulski
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
FETCHING DATA - THE MYSQL WAY
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
SAMPLE QUERIES
— OR —
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
SO, WHAT’S WRONG WITH THAT?
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
BUT…LET’S TEST THE SPEED
• PHP 7.0.4 • MariaDB 10.0.22
500 000 records with random data
+
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
SQL WAY | SPEED TEST
$resultsInMs = [];

$statement = $pdo->prepare('SELECT value FROM t WHERE id=:id LIMIT 1');

for ($i = 1; $i <= 500000; ++$i)

{

$before = microtime(true);


$statement->execute(['id' => $i]);

$data = $statement->fetchColumn();


$after = microtime(true);

$resultsInMs[] = ($after-$before)*1000;

}

$resultInMs = array_sum($resultsInMs)/count($resultsInMs);

echo round($resultInMs, 3) . ' ms.' . PHP_EOL;

echo round(stats_standard_deviation($resultsInMs, true), 3) . ' ms.' .
PHP_EOL;

HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
SQL WAY | TEST RESULTS
Average time: 0.131 ms.
Standard deviation: 0.012 ms.
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
SQL WAY… WITHOUT STEROIDS| SPEED TEST
$resultsInMs = [];

for ($i = 1; $i <= 500000; ++$i)

{

$before = microtime(true);



$data = $pdo

->query('SELECT value FROM t WHERE id='.$i.' LIMIT 1')

->fetchColumn();



$after = microtime(true);

$resultsInMs[] = ($after-$before)*1000;

}

$resultInMs = array_sum($resultsInMs)/count($resultsInMs);

echo round($resultInMs, 3) . ' ms.' . PHP_EOL;

echo round(stats_standard_deviation($resultsInMs, true), 3) . ' ms.' .
PHP_EOL;
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
SQL WAY… WITHOUT STEROIDS| TEST RESULTS
Average time: 0.257 ms.
Standard deviation: 0.074 ms.
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
SQL WAY | EXAMPLES
SQL Prepared Statements AVG: 0.131 ms.
SQL AVG: 0.257 ms.
Wordpress 4.4.2 homepage: 21 SELECT
21 x 0.257 ms. = 5.397 ms.
Where that (sometimes) matters?
• API
• High frequency operations
• Complicated (long running) reports
• Microservices
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
SIMPLE SOLUTION?
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
SQL WAY | SOLUTION OR A HALF-MEASURE?
• Warmup
• Invalidation
Problems:
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
HANDLERSOCKET TO THE RESCUE!
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
HANDLERSOCKET | THEORY
•MySQL based SQL servers plugin
•Text-like binary protocol - not SQL queries
•TCP connection
•Single thread for modifying data
•Multiple threads for reading data
•Coexists with standard way of using MySQL
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
HANDLERSOCKET WAY | SPEED TEST
$indexId = $hs->getIndexId('test', 't', '', 'id,value');

$resultsInMs = [];

for ($i = 1; $i <= 500000; ++$i)

{

$before = microtime(true);



$hs->select($indexId, '=', [$i]);

$data = $hs->readResponse();



$after = microtime(true);

$resultsInMs[] = ($after-$before)*1000;

}

$resultInMs = array_sum($resultsInMs)/(float)count($resultsInMs);

echo round($resultInMs, 3) . ' ms.' . PHP_EOL;

echo round(stats_standard_deviation($resultsInMs, true), 3) . ' ms.' .
PHP_EOL;
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
HANDLERSOCKET WAY | TEST RESULTS
Average time: 0.073 ms.
Standard deviation: 0.009 ms.
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
SQL VS. HANDLERSOCKET
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
SQL VS. HANDLERSOCKET | AVG(FETCHING TIME) BOXING NIGHT
SQL
SQL PS
HS
0 0,065 0,13 0,195 0,26
0,073MS
0,131MS
0,257MS
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
SQL VS. HANDLERSOCKET | STDEV(FETCHING TIME) BOXING NIGHT
SQL
SQL PS
HS
0 0,02 0,04 0,06 0,08
0,009MS
0,012MS
0,074MS
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
OK, BUT WHY IS IT FASTER?
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
SQL VS. HANDLERSOCKET | LEO, WHY?
Few steps less
Few bytes less
• No query parsing
• No query analysis
• No query execution plan
• ~40% smaller request size
• ~40% smaller response size
Less CPU usage
Less network traffic
Based on our examples
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
COMMUNICATION
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
COMMUNICATION | THEORY
• Port 9998
• Port 9999
• Read only
• Multi threaded
• Write allowed
• Single threaded
• One-line request
• One-line response
• Many requests on single connection
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
PROTOCOL
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
PROTOCOL BASICS | THEORY
• Text-like binary protocol
• Message delimiter -> n, 0x0a
• Column delimiter -> t, 0x09
• Null -> 0, 0x00
• Empty string -> tt, tn
• Characters [0x00 - 0x0f] -> prefixed by 0x01 and shifted by 0x40
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
OPEN INDEX | THEORY
P <index_id> <db> <table> <index> <columns> [<fcolumns>]
<index_id>
Opened index identifier, integer, opened until the client connection
is closed
<db> Database name
<table> Table name
<index> Index name or "PRIMARY" to use primary key
<columns> List of columns to return in response, delimited by ","
[<fcolumns>] Optional argument, list of columns to filter result on
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
FIND DATA | THEORY
<index_id> <op> <vlen> <v1> … <vn> [LIM] [IN] [FILTER …]
<index_id> Opened index identifier
<op> Comparison operation to use: =, >, >=, <, <=
<vlen> Number parameters to compare, equal or less than number of
columns in opened index
<v1> Value to compare using <op> with corresponding column from
index
[LIM] <limit> <offset> default values: limit=1, offset=0
[IN] @ <icol> <ivlen> <iv1> ... <ivn>
[FILTER …] <ftyp> <fop> <fcol> <fval>
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
RESPONSE | THEORY
<errorcode> <numcolumns> <r1> ... <rn>
<errorcode>
Request has successfully executed or not.
'0' means success. Non-zero means an error
<numcolumns> Number of columns of the result set
<r1> … <rn> Result set, n equals <numcolumns>
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
RESPONSE | THEORY
„If <errorcode> is non-zero, <numcolumns>
is always 1 and <r1> indicates a
human-readable error message, though
sometimes <r1> is not provided.”
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
SQL TO HANDLERSOCKET | THEORY
SELECT value FROM t WHERE id=1 LIMIT 1
P 1 test t PRIMARY value
= 0 1
1 = 1 1 0 1 600a5841de
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
SUMMARY
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
PROS | SUMMARY
• Stable
• High performance
• Data consistency
• Replication support
• Not dependent on data storage engine
• Shipped with MariaDB, Percona Server
• Still allows to use SQL client/server protocol
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
CONS | SUMMARY
• Filtering only using indexes
• Non-standard protocol
• Very simple authentication (password per port)
• Lack of support for transactions
• Small community
• Rarely used on production
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
KNOWN ISSUES | SUMMARY
• Persistent connections
• Too many indexes (> 1024?)
• Concurrent structure changes via SQL and data
modification via HandlerSocket
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
Q’N’A
Questions?
HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
THANK YOU!
docplanner.com/career
Join us!

Mais conteúdo relacionado

Mais procurados

Sînică Alboaie - Programming for cloud computing Flows of asynchronous messages
Sînică Alboaie - Programming for cloud computing Flows of asynchronous messagesSînică Alboaie - Programming for cloud computing Flows of asynchronous messages
Sînică Alboaie - Programming for cloud computing Flows of asynchronous messages
Codecamp Romania
 
Scala like distributed collections - dumping time-series data with apache spark
Scala like distributed collections - dumping time-series data with apache sparkScala like distributed collections - dumping time-series data with apache spark
Scala like distributed collections - dumping time-series data with apache spark
Demi Ben-Ari
 

Mais procurados (20)

Scala in a wild enterprise
Scala in a wild enterpriseScala in a wild enterprise
Scala in a wild enterprise
 
Cassandra Development Nirvana
Cassandra Development Nirvana Cassandra Development Nirvana
Cassandra Development Nirvana
 
Approaching graph db
Approaching graph dbApproaching graph db
Approaching graph db
 
Building scalable rest service using Akka HTTP
Building scalable rest service using Akka HTTPBuilding scalable rest service using Akka HTTP
Building scalable rest service using Akka HTTP
 
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
 
Understanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersUnderstanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginners
 
Online index rebuild automation
Online index rebuild automationOnline index rebuild automation
Online index rebuild automation
 
Introduction to ScalaZ
Introduction to ScalaZIntroduction to ScalaZ
Introduction to ScalaZ
 
Sînică Alboaie - Programming for cloud computing Flows of asynchronous messages
Sînică Alboaie - Programming for cloud computing Flows of asynchronous messagesSînică Alboaie - Programming for cloud computing Flows of asynchronous messages
Sînică Alboaie - Programming for cloud computing Flows of asynchronous messages
 
ELK Wrestling (Leeds DevOps)
ELK Wrestling (Leeds DevOps)ELK Wrestling (Leeds DevOps)
ELK Wrestling (Leeds DevOps)
 
Apache Cassandra: building a production app on an eventually-consistent DB
Apache Cassandra: building a production app on an eventually-consistent DBApache Cassandra: building a production app on an eventually-consistent DB
Apache Cassandra: building a production app on an eventually-consistent DB
 
CNIT 141 9. Hard Problems
CNIT 141 9. Hard ProblemsCNIT 141 9. Hard Problems
CNIT 141 9. Hard Problems
 
JugMarche: Neo4j 2 (Cypher)
JugMarche: Neo4j 2 (Cypher)JugMarche: Neo4j 2 (Cypher)
JugMarche: Neo4j 2 (Cypher)
 
Building Distributed Systems from Scratch - Part 1
Building Distributed Systems from Scratch - Part 1Building Distributed Systems from Scratch - Part 1
Building Distributed Systems from Scratch - Part 1
 
Monitoring Big Data Systems - "The Simple Way"
Monitoring Big Data Systems - "The Simple Way"Monitoring Big Data Systems - "The Simple Way"
Monitoring Big Data Systems - "The Simple Way"
 
Effectiveness and code optimization in Java
Effectiveness and code optimization in JavaEffectiveness and code optimization in Java
Effectiveness and code optimization in Java
 
Thinking Functionally with Clojure
Thinking Functionally with ClojureThinking Functionally with Clojure
Thinking Functionally with Clojure
 
Scala like distributed collections - dumping time-series data with apache spark
Scala like distributed collections - dumping time-series data with apache sparkScala like distributed collections - dumping time-series data with apache spark
Scala like distributed collections - dumping time-series data with apache spark
 
Loading 350M documents into a large Solr cluster: Presented by Dion Olsthoorn...
Loading 350M documents into a large Solr cluster: Presented by Dion Olsthoorn...Loading 350M documents into a large Solr cluster: Presented by Dion Olsthoorn...
Loading 350M documents into a large Solr cluster: Presented by Dion Olsthoorn...
 
ELK at LinkedIn - Kafka, scaling, lessons learned
ELK at LinkedIn - Kafka, scaling, lessons learnedELK at LinkedIn - Kafka, scaling, lessons learned
ELK at LinkedIn - Kafka, scaling, lessons learned
 

Semelhante a HandlerSocket

Databases in the Cloud - DevDay Austin 2017 Day 2
Databases in the Cloud - DevDay Austin 2017 Day 2Databases in the Cloud - DevDay Austin 2017 Day 2
Databases in the Cloud - DevDay Austin 2017 Day 2
Amazon Web Services
 

Semelhante a HandlerSocket (20)

NoSQL Intro with cassandra
NoSQL Intro with cassandraNoSQL Intro with cassandra
NoSQL Intro with cassandra
 
OscaR.cbls3.0_V7
OscaR.cbls3.0_V7OscaR.cbls3.0_V7
OscaR.cbls3.0_V7
 
SQL Now! How Optiq brings the best of SQL to NoSQL data.
SQL Now! How Optiq brings the best of SQL to NoSQL data.SQL Now! How Optiq brings the best of SQL to NoSQL data.
SQL Now! How Optiq brings the best of SQL to NoSQL data.
 
SFScon18 - Stefano Pampaloni - The SQL revenge
SFScon18 - Stefano Pampaloni - The SQL revengeSFScon18 - Stefano Pampaloni - The SQL revenge
SFScon18 - Stefano Pampaloni - The SQL revenge
 
Ipc mysql php
Ipc mysql php Ipc mysql php
Ipc mysql php
 
Scaling for Performance
Scaling for PerformanceScaling for Performance
Scaling for Performance
 
DataStax C*ollege Credit: What and Why NoSQL?
DataStax C*ollege Credit: What and Why NoSQL?DataStax C*ollege Credit: What and Why NoSQL?
DataStax C*ollege Credit: What and Why NoSQL?
 
Solve it Differently with Reactive Programming
Solve it Differently with Reactive ProgrammingSolve it Differently with Reactive Programming
Solve it Differently with Reactive Programming
 
Predicting SPARQL query execution time and suggesting SPARQL queries based on...
Predicting SPARQL query execution time and suggesting SPARQL queries based on...Predicting SPARQL query execution time and suggesting SPARQL queries based on...
Predicting SPARQL query execution time and suggesting SPARQL queries based on...
 
NOSQL Meets Relational - The MySQL Ecosystem Gains More Flexibility
NOSQL Meets Relational - The MySQL Ecosystem Gains More FlexibilityNOSQL Meets Relational - The MySQL Ecosystem Gains More Flexibility
NOSQL Meets Relational - The MySQL Ecosystem Gains More Flexibility
 
MySQL on Ceph
MySQL on CephMySQL on Ceph
MySQL on Ceph
 
My SQL on Ceph
My SQL on CephMy SQL on Ceph
My SQL on Ceph
 
Databases in the Cloud - DevDay Austin 2017 Day 2
Databases in the Cloud - DevDay Austin 2017 Day 2Databases in the Cloud - DevDay Austin 2017 Day 2
Databases in the Cloud - DevDay Austin 2017 Day 2
 
NoSQL Now! Webinar Series: Innovations in NoSQL Query Languages
NoSQL Now! Webinar Series: Innovations in NoSQL Query Languages  NoSQL Now! Webinar Series: Innovations in NoSQL Query Languages
NoSQL Now! Webinar Series: Innovations in NoSQL Query Languages
 
Is there a SQL for NoSQL?
Is there a SQL for NoSQL?Is there a SQL for NoSQL?
Is there a SQL for NoSQL?
 
0bbleedingedge long-140614012258-phpapp02 lynn-langit
0bbleedingedge long-140614012258-phpapp02 lynn-langit0bbleedingedge long-140614012258-phpapp02 lynn-langit
0bbleedingedge long-140614012258-phpapp02 lynn-langit
 
Bleeding Edge Databases
Bleeding Edge DatabasesBleeding Edge Databases
Bleeding Edge Databases
 
Declarative benchmarking of cassandra and it's data models
Declarative benchmarking of cassandra and it's data modelsDeclarative benchmarking of cassandra and it's data models
Declarative benchmarking of cassandra and it's data models
 
C* Summit 2013: Real-time Analytics using Cassandra, Spark and Shark by Evan ...
C* Summit 2013: Real-time Analytics using Cassandra, Spark and Shark by Evan ...C* Summit 2013: Real-time Analytics using Cassandra, Spark and Shark by Evan ...
C* Summit 2013: Real-time Analytics using Cassandra, Spark and Shark by Evan ...
 
AWS Summit 2013 | Singapore - Understanding Databases Options
AWS Summit 2013 | Singapore - Understanding Databases OptionsAWS Summit 2013 | Singapore - Understanding Databases Options
AWS Summit 2013 | Singapore - Understanding Databases Options
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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...
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
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...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
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?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

HandlerSocket

  • 2. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL ABOUT ME Lukasz Barulski • backend dev AKA IAmDoingEverythingExceptFrontend dev • been with DocPlanner since dinosaurs • kicks butts in MK X /lbarulski /in/lukaszbarulski
  • 3. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL FETCHING DATA - THE MYSQL WAY
  • 4. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL SAMPLE QUERIES — OR —
  • 5. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL SO, WHAT’S WRONG WITH THAT?
  • 6. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL
  • 7. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL BUT…LET’S TEST THE SPEED • PHP 7.0.4 • MariaDB 10.0.22 500 000 records with random data +
  • 8. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL SQL WAY | SPEED TEST $resultsInMs = [];
 $statement = $pdo->prepare('SELECT value FROM t WHERE id=:id LIMIT 1');
 for ($i = 1; $i <= 500000; ++$i)
 {
 $before = microtime(true); 
 $statement->execute(['id' => $i]);
 $data = $statement->fetchColumn(); 
 $after = microtime(true);
 $resultsInMs[] = ($after-$before)*1000;
 }
 $resultInMs = array_sum($resultsInMs)/count($resultsInMs);
 echo round($resultInMs, 3) . ' ms.' . PHP_EOL;
 echo round(stats_standard_deviation($resultsInMs, true), 3) . ' ms.' . PHP_EOL;

  • 9. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL SQL WAY | TEST RESULTS Average time: 0.131 ms. Standard deviation: 0.012 ms.
  • 10. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL SQL WAY… WITHOUT STEROIDS| SPEED TEST $resultsInMs = [];
 for ($i = 1; $i <= 500000; ++$i)
 {
 $before = microtime(true);
 
 $data = $pdo
 ->query('SELECT value FROM t WHERE id='.$i.' LIMIT 1')
 ->fetchColumn();
 
 $after = microtime(true);
 $resultsInMs[] = ($after-$before)*1000;
 }
 $resultInMs = array_sum($resultsInMs)/count($resultsInMs);
 echo round($resultInMs, 3) . ' ms.' . PHP_EOL;
 echo round(stats_standard_deviation($resultsInMs, true), 3) . ' ms.' . PHP_EOL;
  • 11. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL SQL WAY… WITHOUT STEROIDS| TEST RESULTS Average time: 0.257 ms. Standard deviation: 0.074 ms.
  • 12. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL SQL WAY | EXAMPLES SQL Prepared Statements AVG: 0.131 ms. SQL AVG: 0.257 ms. Wordpress 4.4.2 homepage: 21 SELECT 21 x 0.257 ms. = 5.397 ms. Where that (sometimes) matters? • API • High frequency operations • Complicated (long running) reports • Microservices
  • 13. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL SIMPLE SOLUTION?
  • 14. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL SQL WAY | SOLUTION OR A HALF-MEASURE? • Warmup • Invalidation Problems:
  • 15. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL HANDLERSOCKET TO THE RESCUE!
  • 16. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL HANDLERSOCKET | THEORY •MySQL based SQL servers plugin •Text-like binary protocol - not SQL queries •TCP connection •Single thread for modifying data •Multiple threads for reading data •Coexists with standard way of using MySQL
  • 17. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL HANDLERSOCKET WAY | SPEED TEST $indexId = $hs->getIndexId('test', 't', '', 'id,value');
 $resultsInMs = [];
 for ($i = 1; $i <= 500000; ++$i)
 {
 $before = microtime(true);
 
 $hs->select($indexId, '=', [$i]);
 $data = $hs->readResponse();
 
 $after = microtime(true);
 $resultsInMs[] = ($after-$before)*1000;
 }
 $resultInMs = array_sum($resultsInMs)/(float)count($resultsInMs);
 echo round($resultInMs, 3) . ' ms.' . PHP_EOL;
 echo round(stats_standard_deviation($resultsInMs, true), 3) . ' ms.' . PHP_EOL;
  • 18. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL HANDLERSOCKET WAY | TEST RESULTS Average time: 0.073 ms. Standard deviation: 0.009 ms.
  • 19. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL SQL VS. HANDLERSOCKET
  • 20. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL SQL VS. HANDLERSOCKET | AVG(FETCHING TIME) BOXING NIGHT SQL SQL PS HS 0 0,065 0,13 0,195 0,26 0,073MS 0,131MS 0,257MS
  • 21. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL SQL VS. HANDLERSOCKET | STDEV(FETCHING TIME) BOXING NIGHT SQL SQL PS HS 0 0,02 0,04 0,06 0,08 0,009MS 0,012MS 0,074MS
  • 22. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL OK, BUT WHY IS IT FASTER?
  • 23. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL SQL VS. HANDLERSOCKET | LEO, WHY? Few steps less Few bytes less • No query parsing • No query analysis • No query execution plan • ~40% smaller request size • ~40% smaller response size Less CPU usage Less network traffic Based on our examples
  • 24. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL COMMUNICATION
  • 25. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL COMMUNICATION | THEORY • Port 9998 • Port 9999 • Read only • Multi threaded • Write allowed • Single threaded • One-line request • One-line response • Many requests on single connection
  • 26. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL PROTOCOL
  • 27. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL PROTOCOL BASICS | THEORY • Text-like binary protocol • Message delimiter -> n, 0x0a • Column delimiter -> t, 0x09 • Null -> 0, 0x00 • Empty string -> tt, tn • Characters [0x00 - 0x0f] -> prefixed by 0x01 and shifted by 0x40
  • 28. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL OPEN INDEX | THEORY P <index_id> <db> <table> <index> <columns> [<fcolumns>] <index_id> Opened index identifier, integer, opened until the client connection is closed <db> Database name <table> Table name <index> Index name or "PRIMARY" to use primary key <columns> List of columns to return in response, delimited by "," [<fcolumns>] Optional argument, list of columns to filter result on
  • 29. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL FIND DATA | THEORY <index_id> <op> <vlen> <v1> … <vn> [LIM] [IN] [FILTER …] <index_id> Opened index identifier <op> Comparison operation to use: =, >, >=, <, <= <vlen> Number parameters to compare, equal or less than number of columns in opened index <v1> Value to compare using <op> with corresponding column from index [LIM] <limit> <offset> default values: limit=1, offset=0 [IN] @ <icol> <ivlen> <iv1> ... <ivn> [FILTER …] <ftyp> <fop> <fcol> <fval>
  • 30. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL RESPONSE | THEORY <errorcode> <numcolumns> <r1> ... <rn> <errorcode> Request has successfully executed or not. '0' means success. Non-zero means an error <numcolumns> Number of columns of the result set <r1> … <rn> Result set, n equals <numcolumns>
  • 31. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL RESPONSE | THEORY „If <errorcode> is non-zero, <numcolumns> is always 1 and <r1> indicates a human-readable error message, though sometimes <r1> is not provided.”
  • 32. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL SQL TO HANDLERSOCKET | THEORY SELECT value FROM t WHERE id=1 LIMIT 1 P 1 test t PRIMARY value = 0 1 1 = 1 1 0 1 600a5841de
  • 33. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL SUMMARY
  • 34. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL PROS | SUMMARY • Stable • High performance • Data consistency • Replication support • Not dependent on data storage engine • Shipped with MariaDB, Percona Server • Still allows to use SQL client/server protocol
  • 35. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL CONS | SUMMARY • Filtering only using indexes • Non-standard protocol • Very simple authentication (password per port) • Lack of support for transactions • Small community • Rarely used on production
  • 36. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL KNOWN ISSUES | SUMMARY • Persistent connections • Too many indexes (> 1024?) • Concurrent structure changes via SQL and data modification via HandlerSocket
  • 37. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL Q’N’A Questions?
  • 38. HANDLERSOCKET – A NOSQL APPROACH TO MYSQL THANK YOU! docplanner.com/career Join us!