SlideShare a Scribd company logo
1 of 34
Download to read offline
memcached Functions For
MySQL: Seemless caching for
         MySQL
     Patrick Galbraith, Lycos Inc.
About the speaker

Patrick Galbraith

  Principal Software Engineer, Lycos

  16 Years dabbling in Open Source

  Author of Developing Web Applications using..

  Federated Storage Engine, Memcached Functions for
  MySQL/UDFs, DBD::mysql...
What are the memcached Functions for
MySQL?
 A suite of functions available to use with MySQL that allow
 you to store, retrieve and delete data, as well as most of the
 functions/operations that are available with libmemcached
 such as server connectivity to the client, server status, client
 behaviors and more.
 The power of the SQL engine which can be used to initiate
 caching or data retrieval using the result sets from query.
  You can combine the fetching of data from one or more
 tables with the fetching of data from memcached and be
 able to apply any SQL operations on that result set such as
 LIMIT, sorting and other conditional operations.
What are the memcached Functions for
MySQL?
 Written in C using libmemcached and the MySQL UDF API
  Provide get, set, delete, replace, add, flush, stats, behavior
 setting and retrieval, as well as other functionality
 Can be used in stored procedures and triggers
 Allow one to interact with Memcached and MySQL
 independent of the language the application using them is
 written in, or for languages that don’t have clients for
 memcached
  Open Source !!!
What is memcached?

 a high-performance, distributed memory object caching
 system
 Simply a memory server that provides caching layer for
 applications to store data to alleviate database load, as well
 as providing a dictionary, or hash lookup table
  The data stored in memcached is not durable—meaning it’s
 gone when the memcached server is shut down or
 restarted, as well as having no failover or authentication
  Is an LRU (Least Recently Used) cache, which means that
 stored data that is the oldest and least accessed will be
 replaced with newer items when memcached’s memory
 capacity is reached.
  provides expiration timeouts for stored data
What is libmemcached?

 faster memcached client library written in C.
 faster, more efficient, thread-safe, full-featured C library that
 has a significant performance gain over existing client
 libraries.
 more control to affect how the client functions by being able
 to set the client behavior (memcached_behavior_set()) with
 numerous behavior settings such as hashing algorithm or
 whether the client is blocking or non-blocking,
 CAS (Check and Set) support, server host sorting, etc.
How do these UDFs work?

Using both MySQL UDF API and libmemcached
Installation

  Obtain source
  Configure, compile, and install code
  Install functions
      SQL install script
      Perl installation utility
  Post installation check
Obtain source

 http://patg.net/downloads/memcached_functions_mysql-0.9.
tar.gz

or

http://download.tangent.org/memcached_functions_mysql-0.8.
tar.gz
Configure, compile and install the code

Run configure, make, make install

./configure --with-
mysql=/usr/local/mysql/bin/mysql_config --
libdir=/usr/local/mysql/lib/mysql/plugin/

make

make install
Install the functions

  Using SQL file:

mysql -uroot -ps3kr1t < sql/install_functions.sql

  Using the Perl installation utility:

./utils/install.pl --host=localhost --
user=user --password=s3kr1t

(see ./utils/install.pl --help for usage)
Post installation check

Check the mysql schema func table:

mysql> select name, dl from mysql.func where
name like 'memc%';
Using the UDFs

 Connection
 Verifying the connection
 Setting values
 Getting/fetching values
 Increment/Decrement
 Behavioral functions
 Statistical functions
 Utility/Version functions
Connection

mysql> select memc_servers_set('127.0.0.1:
11211');
+-------------------------------------+
| memc_servers_set('127.0.0.1:11211') |
+-------------------------------------+
|                                   0|
+-------------------------------------+
Connection

mysql> select memc_servers_set('127.0.0.1:
11211,
127.0.0.1:112112,
127.0.0.1:112113,
127.0.0.1:112114,
10.20.0.246:11211');
Verifying the connection

mysql> select memc_server_count();
+---------------------+
| memc_server_count() |
+---------------------+
|                   5|
+---------------------+
Setting values

mysql> select memc_set('my_key', 'somevalue');
+---------------------------------+
| memc_set('my_key', 'somevalue') |
+---------------------------------+
|                               0|
+---------------------------------+

mysql> select memc_set_by_key('master1', 'my_key',
'somevalue');
+---------------------------------------------------+
| memc_set_by_key('master1', 'my_key', 'somevalue') |
+---------------------------------------------------+
|                                                  0|
+---------------------------------------------------+
CAS - check and switch

quot;cas is a check and set operation which means 'store this data
but only if no one else has updated since I last fetched it.'quot;
select memc_behavior_set('MEMCACHED_BEHAVIOR_SUPPORT_CAS', 1);
Prepend, append

select memc_set('foo1', ' this value ');

select memc_prepend('foo1', 'before');

select memc_append('foo1', 'after');
Getting/fetching values

mysql> select memc_get('foo1');
+-------------------------+
| memc_get('foo1')        |
+-------------------------+
| before this value after |
+-------------------------+
Incrementing values

select memc_set('counter', 0);
select memc_increment('counter', 1);
select memc_increment('counter', 1);
select memc_increment('counter', 20);

select memc_decrement('counter');
select memc_decrement('counter', 5);
...
Behavioral functions
mysql> select memc_list_behaviors()G
*************************** 1. row ***************************
memc_list_behaviors():
MEMCACHED SERVER BEHAVIORS
MEMCACHED_BEHAVIOR_SUPPORT_CAS
MEMCACHED_BEHAVIOR_NO_BLOCK
MEMCACHED_BEHAVIOR_TCP_NODELAY
MEMCACHED_BEHAVIOR_HASH
MEMCACHED_BEHAVIOR_CACHE_LOOKUPS
MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
MEMCACHED_BEHAVIOR_KETAMA
MEMCACHED_BEHAVIOR_POLL_TIMEOUT
MEMCACHED_BEHAVIOR_RETRY_TIMEOUT
MEMCACHED_BEHAVIOR_DISTRIBUTION
MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
...
Setting a behavior

mysql> select memc_servers_behavior_set
('MEMCACHED_BEHAVIOR_TCP_NODELAY', 1);
+----------------------------------------------------------------+
| memc_servers_behavior_set('MEMCACHED_BEHAVIOR_TCP_NODELAY', 1) |
+----------------------------------------------------------------+
|                                                              0|
+----------------------------------------------------------------+
Distribution types

This function allows you see the different means of distributing
values to servers for use with memc_behavior_set
mysql> select memc_list_distribution_types()G
*************************** 1. row ***************************
memc_list_distribution_types():
MEMACHED_DISTRIBUTION_MODULA
MEMCACHED_DISTRIBUTION_CONSISTENT
MEMCACHED_DISTRIBUTION_KETAMA

mysql> select memc_servers_behavior_get
('MEMCACHED_BEHAVIOR_DISTRIBUTION');
+--------------------------------------------------------------+
| memc_servers_behavior_get('MEMCACHED_BEHAVIOR_DISTRIBUTION') |
+--------------------------------------------------------------+
| MEMCACHED_DISTRIBUTION_MODULA                                |
+--------------------------------------------------------------+
Hashing types

mysql> select memc_list_hash_types()G
*************************** 1. row ***************************
memc_list_hash_types():
MEMCACHED_HASH_DEFAULT
MEMCACHED_HASH_MD5
MEMCACHED_HASH_CRC
MEMCACHED_HASH_FNV1_64
MEMCACHED_HASH_FNV1A_64
MEMCACHED_HASH_FNV1_32
MEMCACHED_HASH_FNV1A_32
MEMCACHED_HASH_JENKINS
MEMCACHED_HASH_HSI
Hashing types
mysql> select memc_servers_behavior_get('MEMCACHED_BEHAVIOR_HASH');
+------------------------------------------------------+
| memc_servers_behavior_get('MEMCACHED_BEHAVIOR_HASH') |
+------------------------------------------------------+
| MEMCACHED_HASH_DEFAULT                               |
+------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select memc_servers_behavior_set('MEMCACHED_BEHAVIOR_HASH',
'MEMCACHED_HASH_DEFAULT');
Statistical functions

select memc_stats('127.0.0.1:11214');

Server: 127.0.0.1 (11214)
     pid: 15470
     uptime: 1634
     time: 1240205306
     version: 1.2.6
     pointer_size: 64
     rusage_user: 0.15997
     rusage_system: 0.23996
     curr_items: 8
     total_items: 8
     bytes: 640
     curr_connections: 4
     total_connections: 27
     connection_structures: 5
     ...
Statistical functions

mysql> select memc_stat_get_keys();

mysql> select memc_stat_get_value('127.0.0.1:11214',
'total_items');
+-------------------------------------------------------+
| memc_stat_get_value('127.0.0.1:11214', 'total_items') |
+-------------------------------------------------------+
|8                                                      |
+-------------------------------------------------------+
Version info

mysql> select memc_udf_version();
+--------------------+
| memc_udf_version() |
+--------------------+
| 0.9                |
+--------------------+

mysql> select memc_server_version('127.0.0.1:11212')

mysql> select memc_libmemcached_version();
+-----------------------------+
| memc_libmemcached_version() |
+-----------------------------+
| 0.27                        |
+-----------------------------+
Application

* Triggers (see sql/trigger_fun.sql)
* Stored procedures
* You can use these with DBI programs, storing Perl objects
using storable
* Aggregation in select
* Anything you can think of!
Serialization (set)
sub memc_set {
  my ($this, $key, $value)= @_;
  my $sth = $this->{dbh}->prepare_cached
('SELECT memc_set(?, ?)');

    my $storable_value = ref $value ?
         nfreeze($value) : $value;
    $sth->execute($key, $storable_value);
    my $stored = $sth->fetchrow_arrayref();
    # returns 0 on success, greater than 0 error
    return $stored->[0];

}
Serialization (get)
sub memc_get {
  my ($this, $key)= @_;
  my $de_serialized;
  my $sth= $this->{dbh}->prepare_cached('SELECT memc_get
(?)');

 $sth->execute($key);
 my $stored= $sth->fetchrow_arrayref();
 # will be 1 or 0

if (defined $stored->[0]) {
    eval { $de_serialized = thaw($stored->[0])};
    return $@ ? $stored->[0] : $de_serialized;
  }
  else {
    return undef;
  }
}
Using with other UDFs (Gearman!)
DELIMITER |
DROP TRIGGER IF EXISTS urls_stored_insert |
CREATE TRIGGER urls_stored_insert
BEFORE INSERT ON urls_stored
FOR EACH ROW BEGIN
  SET @count = memc_increment('urls_stored');
  SET @index_count = memc_increment('index_counter');
  IF @count > 5 THEN
    SET @gd= gman_servers_set('127.0.0.1:4730');
    SET @gd= gman_do_background('url_process', NEW.url);
    SET @reset = memc_set('urls_stored', 0);
  END IF;
  IF @index_count > 20 THEN
    SET @gd= gman_servers_set('127.0.0.1:4730');
    SET @gd = gman_do_background('indexer', NEW.url);
    SET @reset = memc_set('index_counter', 0);
  END IF;
END |
Gearman example

More Related Content

What's hot

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 MySQL InnoDB Cluster
Introduction to MySQL InnoDB ClusterIntroduction to MySQL InnoDB Cluster
Introduction to MySQL InnoDB ClusterI Goo Lee
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionSveta Smirnova
 
Optimizer Cost Model MySQL 5.7
Optimizer Cost Model MySQL 5.7Optimizer Cost Model MySQL 5.7
Optimizer Cost Model MySQL 5.7I Goo Lee
 
Modern query optimisation features in MySQL 8.
Modern query optimisation features in MySQL 8.Modern query optimisation features in MySQL 8.
Modern query optimisation features in MySQL 8.Mydbops
 
UKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL TuningUKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL TuningFromDual GmbH
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionSveta Smirnova
 
MariaDB for developers
MariaDB for developersMariaDB for developers
MariaDB for developersColin Charles
 
Troubleshooting MySQL Performance
Troubleshooting MySQL PerformanceTroubleshooting MySQL Performance
Troubleshooting MySQL PerformanceSveta Smirnova
 
MySQL Document Store
MySQL Document StoreMySQL Document Store
MySQL Document StoreI Goo Lee
 
Basic MySQL Troubleshooting for Oracle Database Administrators
Basic MySQL Troubleshooting for Oracle Database AdministratorsBasic MySQL Troubleshooting for Oracle Database Administrators
Basic MySQL Troubleshooting for Oracle Database AdministratorsSveta Smirnova
 
Database administration commands
Database administration commands Database administration commands
Database administration commands Varsha Ajith
 
[2019] 200만 동접 게임을 위한 MySQL 샤딩
[2019] 200만 동접 게임을 위한 MySQL 샤딩[2019] 200만 동접 게임을 위한 MySQL 샤딩
[2019] 200만 동접 게임을 위한 MySQL 샤딩NHN FORWARD
 
Basic MySQL Troubleshooting for Oracle DBAs
Basic MySQL Troubleshooting for Oracle DBAsBasic MySQL Troubleshooting for Oracle DBAs
Basic MySQL Troubleshooting for Oracle DBAsSveta Smirnova
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingSveta Smirnova
 

What's hot (19)

Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Introduction to MySQL InnoDB Cluster
Introduction to MySQL InnoDB ClusterIntroduction to MySQL InnoDB Cluster
Introduction to MySQL InnoDB Cluster
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in action
 
PPT
PPTPPT
PPT
 
Optimizer Cost Model MySQL 5.7
Optimizer Cost Model MySQL 5.7Optimizer Cost Model MySQL 5.7
Optimizer Cost Model MySQL 5.7
 
Modern query optimisation features in MySQL 8.
Modern query optimisation features in MySQL 8.Modern query optimisation features in MySQL 8.
Modern query optimisation features in MySQL 8.
 
UKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL TuningUKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL Tuning
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in action
 
MariaDB for developers
MariaDB for developersMariaDB for developers
MariaDB for developers
 
MySQLinsanity
MySQLinsanityMySQLinsanity
MySQLinsanity
 
Troubleshooting MySQL Performance
Troubleshooting MySQL PerformanceTroubleshooting MySQL Performance
Troubleshooting MySQL Performance
 
MySQL Document Store
MySQL Document StoreMySQL Document Store
MySQL Document Store
 
Basic MySQL Troubleshooting for Oracle Database Administrators
Basic MySQL Troubleshooting for Oracle Database AdministratorsBasic MySQL Troubleshooting for Oracle Database Administrators
Basic MySQL Troubleshooting for Oracle Database Administrators
 
Database administration commands
Database administration commands Database administration commands
Database administration commands
 
MySQL SQL Tutorial
MySQL SQL TutorialMySQL SQL Tutorial
MySQL SQL Tutorial
 
[2019] 200만 동접 게임을 위한 MySQL 샤딩
[2019] 200만 동접 게임을 위한 MySQL 샤딩[2019] 200만 동접 게임을 위한 MySQL 샤딩
[2019] 200만 동접 게임을 위한 MySQL 샤딩
 
Basic MySQL Troubleshooting for Oracle DBAs
Basic MySQL Troubleshooting for Oracle DBAsBasic MySQL Troubleshooting for Oracle DBAs
Basic MySQL Troubleshooting for Oracle DBAs
 
Oracle ORA Errors
Oracle ORA ErrorsOracle ORA Errors
Oracle ORA Errors
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
 

Viewers also liked

Inno Db Performance And Usability Patches
Inno Db Performance And Usability PatchesInno Db Performance And Usability Patches
Inno Db Performance And Usability PatchesMySQLConference
 
Writing Efficient Java Applications For My Sql Cluster Using Ndbj
Writing Efficient Java Applications For My Sql Cluster Using NdbjWriting Efficient Java Applications For My Sql Cluster Using Ndbj
Writing Efficient Java Applications For My Sql Cluster Using NdbjMySQLConference
 
Getting The Most Out Of My Sql Enterprise Monitor 20
Getting The Most Out Of My Sql Enterprise Monitor 20Getting The Most Out Of My Sql Enterprise Monitor 20
Getting The Most Out Of My Sql Enterprise Monitor 20MySQLConference
 
Using Open Source Bi In The Real World
Using Open Source Bi In The Real WorldUsing Open Source Bi In The Real World
Using Open Source Bi In The Real WorldMySQLConference
 
My Sql And Search At Craigslist
My Sql And Search At CraigslistMy Sql And Search At Craigslist
My Sql And Search At CraigslistMySQLConference
 
Unleash The Power Of Your Data Using Open Source Business Intelligence
Unleash The Power Of Your Data Using Open Source Business IntelligenceUnleash The Power Of Your Data Using Open Source Business Intelligence
Unleash The Power Of Your Data Using Open Source Business IntelligenceMySQLConference
 

Viewers also liked (6)

Inno Db Performance And Usability Patches
Inno Db Performance And Usability PatchesInno Db Performance And Usability Patches
Inno Db Performance And Usability Patches
 
Writing Efficient Java Applications For My Sql Cluster Using Ndbj
Writing Efficient Java Applications For My Sql Cluster Using NdbjWriting Efficient Java Applications For My Sql Cluster Using Ndbj
Writing Efficient Java Applications For My Sql Cluster Using Ndbj
 
Getting The Most Out Of My Sql Enterprise Monitor 20
Getting The Most Out Of My Sql Enterprise Monitor 20Getting The Most Out Of My Sql Enterprise Monitor 20
Getting The Most Out Of My Sql Enterprise Monitor 20
 
Using Open Source Bi In The Real World
Using Open Source Bi In The Real WorldUsing Open Source Bi In The Real World
Using Open Source Bi In The Real World
 
My Sql And Search At Craigslist
My Sql And Search At CraigslistMy Sql And Search At Craigslist
My Sql And Search At Craigslist
 
Unleash The Power Of Your Data Using Open Source Business Intelligence
Unleash The Power Of Your Data Using Open Source Business IntelligenceUnleash The Power Of Your Data Using Open Source Business Intelligence
Unleash The Power Of Your Data Using Open Source Business Intelligence
 

Similar to Memcached Functions For My Sql Seemless Caching In My Sql

MySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxMySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxNeoClova
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)Valeriy Kravchuk
 
MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 MinutesSveta Smirnova
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012Roland Bouman
 
Percona Live 2019 - MySQL Security
Percona Live 2019 - MySQL SecurityPercona Live 2019 - MySQL Security
Percona Live 2019 - MySQL SecurityVinicius M Grippa
 
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricksQuery Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricksJaime Crespo
 
Mysql nowwhat
Mysql nowwhatMysql nowwhat
Mysql nowwhatsqlhjalp
 
HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)akirahiguchi
 
Confoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesConfoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesDave Stokes
 
MySQL sys schema deep dive
MySQL sys schema deep diveMySQL sys schema deep dive
MySQL sys schema deep diveMark Leith
 
ProxySQL & PXC(Query routing and Failover Test)
ProxySQL & PXC(Query routing and Failover Test)ProxySQL & PXC(Query routing and Failover Test)
ProxySQL & PXC(Query routing and Failover Test)YoungHeon (Roy) Kim
 
Highload Perf Tuning
Highload Perf TuningHighload Perf Tuning
Highload Perf TuningHighLoad2009
 
Observability of InfluxDB IOx: Tracing, Metrics and System Tables
Observability of InfluxDB IOx: Tracing, Metrics and System TablesObservability of InfluxDB IOx: Tracing, Metrics and System Tables
Observability of InfluxDB IOx: Tracing, Metrics and System TablesInfluxData
 
MySQL 5.7 - What's new and How to upgrade
MySQL 5.7 - What's new and How to upgradeMySQL 5.7 - What's new and How to upgrade
MySQL 5.7 - What's new and How to upgradeAbel Flórez
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsUlf Wendel
 
ProxySQL Cluster - Percona Live 2022
ProxySQL Cluster - Percona Live 2022ProxySQL Cluster - Percona Live 2022
ProxySQL Cluster - Percona Live 2022René Cannaò
 
Enhancements that will make your sql database roar sp1 edition sql bits 2017
Enhancements that will make your sql database roar sp1 edition sql bits 2017Enhancements that will make your sql database roar sp1 edition sql bits 2017
Enhancements that will make your sql database roar sp1 edition sql bits 2017Bob Ward
 

Similar to Memcached Functions For My Sql Seemless Caching In My Sql (20)

Mysql tracing
Mysql tracingMysql tracing
Mysql tracing
 
MySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxMySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptx
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
 
MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 Minutes
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Percona Live 2019 - MySQL Security
Percona Live 2019 - MySQL SecurityPercona Live 2019 - MySQL Security
Percona Live 2019 - MySQL Security
 
Perf Tuning Short
Perf Tuning ShortPerf Tuning Short
Perf Tuning Short
 
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricksQuery Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
 
Mysql nowwhat
Mysql nowwhatMysql nowwhat
Mysql nowwhat
 
HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)
 
Confoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesConfoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New Features
 
MySQL sys schema deep dive
MySQL sys schema deep diveMySQL sys schema deep dive
MySQL sys schema deep dive
 
ProxySQL & PXC(Query routing and Failover Test)
ProxySQL & PXC(Query routing and Failover Test)ProxySQL & PXC(Query routing and Failover Test)
ProxySQL & PXC(Query routing and Failover Test)
 
Highload Perf Tuning
Highload Perf TuningHighload Perf Tuning
Highload Perf Tuning
 
Observability of InfluxDB IOx: Tracing, Metrics and System Tables
Observability of InfluxDB IOx: Tracing, Metrics and System TablesObservability of InfluxDB IOx: Tracing, Metrics and System Tables
Observability of InfluxDB IOx: Tracing, Metrics and System Tables
 
MySQL 5.7 - What's new and How to upgrade
MySQL 5.7 - What's new and How to upgradeMySQL 5.7 - What's new and How to upgrade
MySQL 5.7 - What's new and How to upgrade
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIs
 
ProxySQL Cluster - Percona Live 2022
ProxySQL Cluster - Percona Live 2022ProxySQL Cluster - Percona Live 2022
ProxySQL Cluster - Percona Live 2022
 
Enhancements that will make your sql database roar sp1 edition sql bits 2017
Enhancements that will make your sql database roar sp1 edition sql bits 2017Enhancements that will make your sql database roar sp1 edition sql bits 2017
Enhancements that will make your sql database roar sp1 edition sql bits 2017
 
Aspects of 10 Tuning
Aspects of 10 TuningAspects of 10 Tuning
Aspects of 10 Tuning
 

More from MySQLConference

Partitioning Under The Hood
Partitioning Under The HoodPartitioning Under The Hood
Partitioning Under The HoodMySQLConference
 
Tricks And Tradeoffs Of Deploying My Sql Clusters In The Cloud
Tricks And Tradeoffs Of Deploying My Sql Clusters In The CloudTricks And Tradeoffs Of Deploying My Sql Clusters In The Cloud
Tricks And Tradeoffs Of Deploying My Sql Clusters In The CloudMySQLConference
 
D Trace Support In My Sql Guide To Solving Reallife Performance Problems
D Trace Support In My Sql Guide To Solving Reallife Performance ProblemsD Trace Support In My Sql Guide To Solving Reallife Performance Problems
D Trace Support In My Sql Guide To Solving Reallife Performance ProblemsMySQLConference
 
My Sql Performance On Ec2
My Sql Performance On Ec2My Sql Performance On Ec2
My Sql Performance On Ec2MySQLConference
 
Solving Common Sql Problems With The Seq Engine
Solving Common Sql Problems With The Seq EngineSolving Common Sql Problems With The Seq Engine
Solving Common Sql Problems With The Seq EngineMySQLConference
 
Using Continuous Etl With Real Time Queries To Eliminate My Sql Bottlenecks
Using Continuous Etl With Real Time Queries To Eliminate My Sql BottlenecksUsing Continuous Etl With Real Time Queries To Eliminate My Sql Bottlenecks
Using Continuous Etl With Real Time Queries To Eliminate My Sql BottlenecksMySQLConference
 
Make Your Life Easier With Maatkit
Make Your Life Easier With MaatkitMake Your Life Easier With Maatkit
Make Your Life Easier With MaatkitMySQLConference
 
Wide Open Spaces Using My Sql As A Web Mapping Service Backend
Wide Open Spaces Using My Sql As A Web Mapping Service BackendWide Open Spaces Using My Sql As A Web Mapping Service Backend
Wide Open Spaces Using My Sql As A Web Mapping Service BackendMySQLConference
 
Inno Db Internals Inno Db File Formats And Source Code Structure
Inno Db Internals Inno Db File Formats And Source Code StructureInno Db Internals Inno Db File Formats And Source Code Structure
Inno Db Internals Inno Db File Formats And Source Code StructureMySQLConference
 
My Sql High Availability With A Punch Drbd 83 And Drbd For Dolphin Express
My Sql High Availability With A Punch Drbd 83 And Drbd For Dolphin ExpressMy Sql High Availability With A Punch Drbd 83 And Drbd For Dolphin Express
My Sql High Availability With A Punch Drbd 83 And Drbd For Dolphin ExpressMySQLConference
 

More from MySQLConference (11)

Partitioning Under The Hood
Partitioning Under The HoodPartitioning Under The Hood
Partitioning Under The Hood
 
Tricks And Tradeoffs Of Deploying My Sql Clusters In The Cloud
Tricks And Tradeoffs Of Deploying My Sql Clusters In The CloudTricks And Tradeoffs Of Deploying My Sql Clusters In The Cloud
Tricks And Tradeoffs Of Deploying My Sql Clusters In The Cloud
 
D Trace Support In My Sql Guide To Solving Reallife Performance Problems
D Trace Support In My Sql Guide To Solving Reallife Performance ProblemsD Trace Support In My Sql Guide To Solving Reallife Performance Problems
D Trace Support In My Sql Guide To Solving Reallife Performance Problems
 
My Sql Performance On Ec2
My Sql Performance On Ec2My Sql Performance On Ec2
My Sql Performance On Ec2
 
The Smug Mug Tale
The Smug Mug TaleThe Smug Mug Tale
The Smug Mug Tale
 
Solving Common Sql Problems With The Seq Engine
Solving Common Sql Problems With The Seq EngineSolving Common Sql Problems With The Seq Engine
Solving Common Sql Problems With The Seq Engine
 
Using Continuous Etl With Real Time Queries To Eliminate My Sql Bottlenecks
Using Continuous Etl With Real Time Queries To Eliminate My Sql BottlenecksUsing Continuous Etl With Real Time Queries To Eliminate My Sql Bottlenecks
Using Continuous Etl With Real Time Queries To Eliminate My Sql Bottlenecks
 
Make Your Life Easier With Maatkit
Make Your Life Easier With MaatkitMake Your Life Easier With Maatkit
Make Your Life Easier With Maatkit
 
Wide Open Spaces Using My Sql As A Web Mapping Service Backend
Wide Open Spaces Using My Sql As A Web Mapping Service BackendWide Open Spaces Using My Sql As A Web Mapping Service Backend
Wide Open Spaces Using My Sql As A Web Mapping Service Backend
 
Inno Db Internals Inno Db File Formats And Source Code Structure
Inno Db Internals Inno Db File Formats And Source Code StructureInno Db Internals Inno Db File Formats And Source Code Structure
Inno Db Internals Inno Db File Formats And Source Code Structure
 
My Sql High Availability With A Punch Drbd 83 And Drbd For Dolphin Express
My Sql High Availability With A Punch Drbd 83 And Drbd For Dolphin ExpressMy Sql High Availability With A Punch Drbd 83 And Drbd For Dolphin Express
My Sql High Availability With A Punch Drbd 83 And Drbd For Dolphin Express
 

Recently uploaded

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 

Recently uploaded (20)

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 

Memcached Functions For My Sql Seemless Caching In My Sql

  • 1. memcached Functions For MySQL: Seemless caching for MySQL Patrick Galbraith, Lycos Inc.
  • 2. About the speaker Patrick Galbraith Principal Software Engineer, Lycos 16 Years dabbling in Open Source Author of Developing Web Applications using.. Federated Storage Engine, Memcached Functions for MySQL/UDFs, DBD::mysql...
  • 3. What are the memcached Functions for MySQL? A suite of functions available to use with MySQL that allow you to store, retrieve and delete data, as well as most of the functions/operations that are available with libmemcached such as server connectivity to the client, server status, client behaviors and more. The power of the SQL engine which can be used to initiate caching or data retrieval using the result sets from query. You can combine the fetching of data from one or more tables with the fetching of data from memcached and be able to apply any SQL operations on that result set such as LIMIT, sorting and other conditional operations.
  • 4. What are the memcached Functions for MySQL? Written in C using libmemcached and the MySQL UDF API Provide get, set, delete, replace, add, flush, stats, behavior setting and retrieval, as well as other functionality Can be used in stored procedures and triggers Allow one to interact with Memcached and MySQL independent of the language the application using them is written in, or for languages that don’t have clients for memcached Open Source !!!
  • 5. What is memcached? a high-performance, distributed memory object caching system Simply a memory server that provides caching layer for applications to store data to alleviate database load, as well as providing a dictionary, or hash lookup table The data stored in memcached is not durable—meaning it’s gone when the memcached server is shut down or restarted, as well as having no failover or authentication Is an LRU (Least Recently Used) cache, which means that stored data that is the oldest and least accessed will be replaced with newer items when memcached’s memory capacity is reached. provides expiration timeouts for stored data
  • 6. What is libmemcached? faster memcached client library written in C. faster, more efficient, thread-safe, full-featured C library that has a significant performance gain over existing client libraries. more control to affect how the client functions by being able to set the client behavior (memcached_behavior_set()) with numerous behavior settings such as hashing algorithm or whether the client is blocking or non-blocking, CAS (Check and Set) support, server host sorting, etc.
  • 7. How do these UDFs work? Using both MySQL UDF API and libmemcached
  • 8. Installation Obtain source Configure, compile, and install code Install functions SQL install script Perl installation utility Post installation check
  • 10. Configure, compile and install the code Run configure, make, make install ./configure --with- mysql=/usr/local/mysql/bin/mysql_config -- libdir=/usr/local/mysql/lib/mysql/plugin/ make make install
  • 11. Install the functions Using SQL file: mysql -uroot -ps3kr1t < sql/install_functions.sql Using the Perl installation utility: ./utils/install.pl --host=localhost -- user=user --password=s3kr1t (see ./utils/install.pl --help for usage)
  • 12. Post installation check Check the mysql schema func table: mysql> select name, dl from mysql.func where name like 'memc%';
  • 13. Using the UDFs Connection Verifying the connection Setting values Getting/fetching values Increment/Decrement Behavioral functions Statistical functions Utility/Version functions
  • 14. Connection mysql> select memc_servers_set('127.0.0.1: 11211'); +-------------------------------------+ | memc_servers_set('127.0.0.1:11211') | +-------------------------------------+ | 0| +-------------------------------------+
  • 16. Verifying the connection mysql> select memc_server_count(); +---------------------+ | memc_server_count() | +---------------------+ | 5| +---------------------+
  • 17. Setting values mysql> select memc_set('my_key', 'somevalue'); +---------------------------------+ | memc_set('my_key', 'somevalue') | +---------------------------------+ | 0| +---------------------------------+ mysql> select memc_set_by_key('master1', 'my_key', 'somevalue'); +---------------------------------------------------+ | memc_set_by_key('master1', 'my_key', 'somevalue') | +---------------------------------------------------+ | 0| +---------------------------------------------------+
  • 18. CAS - check and switch quot;cas is a check and set operation which means 'store this data but only if no one else has updated since I last fetched it.'quot; select memc_behavior_set('MEMCACHED_BEHAVIOR_SUPPORT_CAS', 1);
  • 19. Prepend, append select memc_set('foo1', ' this value '); select memc_prepend('foo1', 'before'); select memc_append('foo1', 'after');
  • 20. Getting/fetching values mysql> select memc_get('foo1'); +-------------------------+ | memc_get('foo1') | +-------------------------+ | before this value after | +-------------------------+
  • 21. Incrementing values select memc_set('counter', 0); select memc_increment('counter', 1); select memc_increment('counter', 1); select memc_increment('counter', 20); select memc_decrement('counter'); select memc_decrement('counter', 5); ...
  • 22. Behavioral functions mysql> select memc_list_behaviors()G *************************** 1. row *************************** memc_list_behaviors(): MEMCACHED SERVER BEHAVIORS MEMCACHED_BEHAVIOR_SUPPORT_CAS MEMCACHED_BEHAVIOR_NO_BLOCK MEMCACHED_BEHAVIOR_TCP_NODELAY MEMCACHED_BEHAVIOR_HASH MEMCACHED_BEHAVIOR_CACHE_LOOKUPS MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE MEMCACHED_BEHAVIOR_BUFFER_REQUESTS MEMCACHED_BEHAVIOR_KETAMA MEMCACHED_BEHAVIOR_POLL_TIMEOUT MEMCACHED_BEHAVIOR_RETRY_TIMEOUT MEMCACHED_BEHAVIOR_DISTRIBUTION MEMCACHED_BEHAVIOR_BUFFER_REQUESTS ...
  • 23. Setting a behavior mysql> select memc_servers_behavior_set ('MEMCACHED_BEHAVIOR_TCP_NODELAY', 1); +----------------------------------------------------------------+ | memc_servers_behavior_set('MEMCACHED_BEHAVIOR_TCP_NODELAY', 1) | +----------------------------------------------------------------+ | 0| +----------------------------------------------------------------+
  • 24. Distribution types This function allows you see the different means of distributing values to servers for use with memc_behavior_set mysql> select memc_list_distribution_types()G *************************** 1. row *************************** memc_list_distribution_types(): MEMACHED_DISTRIBUTION_MODULA MEMCACHED_DISTRIBUTION_CONSISTENT MEMCACHED_DISTRIBUTION_KETAMA mysql> select memc_servers_behavior_get ('MEMCACHED_BEHAVIOR_DISTRIBUTION'); +--------------------------------------------------------------+ | memc_servers_behavior_get('MEMCACHED_BEHAVIOR_DISTRIBUTION') | +--------------------------------------------------------------+ | MEMCACHED_DISTRIBUTION_MODULA | +--------------------------------------------------------------+
  • 25. Hashing types mysql> select memc_list_hash_types()G *************************** 1. row *************************** memc_list_hash_types(): MEMCACHED_HASH_DEFAULT MEMCACHED_HASH_MD5 MEMCACHED_HASH_CRC MEMCACHED_HASH_FNV1_64 MEMCACHED_HASH_FNV1A_64 MEMCACHED_HASH_FNV1_32 MEMCACHED_HASH_FNV1A_32 MEMCACHED_HASH_JENKINS MEMCACHED_HASH_HSI
  • 26. Hashing types mysql> select memc_servers_behavior_get('MEMCACHED_BEHAVIOR_HASH'); +------------------------------------------------------+ | memc_servers_behavior_get('MEMCACHED_BEHAVIOR_HASH') | +------------------------------------------------------+ | MEMCACHED_HASH_DEFAULT | +------------------------------------------------------+ 1 row in set (0.00 sec) mysql> select memc_servers_behavior_set('MEMCACHED_BEHAVIOR_HASH', 'MEMCACHED_HASH_DEFAULT');
  • 27. Statistical functions select memc_stats('127.0.0.1:11214'); Server: 127.0.0.1 (11214) pid: 15470 uptime: 1634 time: 1240205306 version: 1.2.6 pointer_size: 64 rusage_user: 0.15997 rusage_system: 0.23996 curr_items: 8 total_items: 8 bytes: 640 curr_connections: 4 total_connections: 27 connection_structures: 5 ...
  • 28. Statistical functions mysql> select memc_stat_get_keys(); mysql> select memc_stat_get_value('127.0.0.1:11214', 'total_items'); +-------------------------------------------------------+ | memc_stat_get_value('127.0.0.1:11214', 'total_items') | +-------------------------------------------------------+ |8 | +-------------------------------------------------------+
  • 29. Version info mysql> select memc_udf_version(); +--------------------+ | memc_udf_version() | +--------------------+ | 0.9 | +--------------------+ mysql> select memc_server_version('127.0.0.1:11212') mysql> select memc_libmemcached_version(); +-----------------------------+ | memc_libmemcached_version() | +-----------------------------+ | 0.27 | +-----------------------------+
  • 30. Application * Triggers (see sql/trigger_fun.sql) * Stored procedures * You can use these with DBI programs, storing Perl objects using storable * Aggregation in select * Anything you can think of!
  • 31. Serialization (set) sub memc_set { my ($this, $key, $value)= @_; my $sth = $this->{dbh}->prepare_cached ('SELECT memc_set(?, ?)'); my $storable_value = ref $value ? nfreeze($value) : $value; $sth->execute($key, $storable_value); my $stored = $sth->fetchrow_arrayref(); # returns 0 on success, greater than 0 error return $stored->[0]; }
  • 32. Serialization (get) sub memc_get { my ($this, $key)= @_; my $de_serialized; my $sth= $this->{dbh}->prepare_cached('SELECT memc_get (?)'); $sth->execute($key); my $stored= $sth->fetchrow_arrayref(); # will be 1 or 0 if (defined $stored->[0]) { eval { $de_serialized = thaw($stored->[0])}; return $@ ? $stored->[0] : $de_serialized; } else { return undef; } }
  • 33. Using with other UDFs (Gearman!) DELIMITER | DROP TRIGGER IF EXISTS urls_stored_insert | CREATE TRIGGER urls_stored_insert BEFORE INSERT ON urls_stored FOR EACH ROW BEGIN SET @count = memc_increment('urls_stored'); SET @index_count = memc_increment('index_counter'); IF @count > 5 THEN SET @gd= gman_servers_set('127.0.0.1:4730'); SET @gd= gman_do_background('url_process', NEW.url); SET @reset = memc_set('urls_stored', 0); END IF; IF @index_count > 20 THEN SET @gd= gman_servers_set('127.0.0.1:4730'); SET @gd = gman_do_background('indexer', NEW.url); SET @reset = memc_set('index_counter', 0); END IF; END |