MongoDB Scaling Workshop for php[tek]

This commit is contained in:
Derick Rethans
2018-05-27 14:56:13 +01:00
parent d8ea64ccc7
commit 44d3d3798b
14 changed files with 328 additions and 73 deletions

151
mongodb-tek18.xml Normal file
View File

@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="utf-8"?>
<presentation css="10gen-strict.css">
<topic>MongoDB</topic>
<title>Scaling MongoDB Workshop</title>
<event>php[tek]</event>
<location>Atlanta, GA, USA</location>
<date>May 30th, 2018</date>
<speaker>Derick Rethans</speaker>
<email>derick@mongodb.com</email>
<twitter>derickr</twitter>
<url>http://derickrethans.nl/talks.html</url>
<joindin>https://joind.in/23167</joindin>
<slide>slides/mongodb/title.xml</slide>
<slide>slides/mongodb/databasefield.xml</slide>
<slide>slides/mongodb/nosql.xml</slide>
<slide>slides/mongodb/cap.xml</slide>
<slide>slides/mongodb/new-architecture.xml</slide>
<slide>slides/mongodb/collections-documents.xml</slide>
<slide>slides/mongodb/document-complex.xml</slide>
<slide>slides/mongodb/phplib-intro.xml</slide>
<slide>slides/mongodb/phplib-crud.xml</slide>
<slide>slides/mongodb/query-side-by-side.xml</slide>
<!-- REPLICATION -->
<slide>slides/mongodb/section-replication.xml</slide>
<slide>slides/mongodb/repl-use-cases.xml</slide>
<slide>slides/mongodb/repl-types-of-outage.xml</slide>
<slide>slides/mongodb/repl-features.xml</slide>
<slide>slides/mongodb/repl-works-basic.xml</slide>
<slide>slides/mongodb/repl-works-normal.xml</slide>
<slide>slides/mongodb/repl-works-failover1.xml</slide>
<slide>slides/mongodb/repl-works-failover2.xml</slide>
<slide>slides/mongodb/repl-works-failover3.xml</slide>
<slide>slides/mongodb/repl-works-failover4.xml</slide>
<slide>slides/mongodb/repl-oplog.xml</slide>
<slide>slides/mongodb/php-connection-string.xml</slide>
<slide>slides/mongodb/repl-managing.xml</slide>
<slide>slides/mongodb/repl-priorities1.xml</slide>
<slide>slides/mongodb/repl-priorities2.xml</slide>
<slide>slides/mongodb/repl-priorities3.xml</slide>
<slide>slides/mongodb/read-preference2.xml</slide>
<slide>slides/mongodb/read-preference.xml</slide>
<slide>slides/mongodb/repl-write-concern.xml</slide>
<slide>slides/mongodb/repl-eventual-consistency.xml</slide>
<slide>slides/mongodb/repl-read-concern.xml</slide>
<slide>slides/mongodb/repl-features2.xml</slide>
<!-- FIRST EXCERCISE -->
<slide>slides/mongodb/excercise.xml</slide>
<slide>slides/mongodb/replication-setup.xml</slide>
<slide>slides/mongodb/replication-exercise-script.xml</slide>
<slide>slides/mongodb/repl-scenarios.xml</slide>
<slide>slides/mongodb/repl-single.xml</slide>
<slide>slides/mongodb/repl-set1.xml</slide>
<slide>slides/mongodb/repl-set2.xml</slide>
<slide>slides/mongodb/repl-set3.xml</slide>
<slide>slides/mongodb/repl-set4.xml</slide>
<slide>slides/mongodb/repl-set5.xml</slide>
<slide>slides/mongodb/repl-typical.xml</slide>
<slide>slides/mongodb/atlas.xml</slide>
<!-- SHARDING -->
<slide>slides/mongodb/section-sharding.xml</slide>
<slide>slides/mongodb/sharding-vertical-scale.xml</slide>
<slide>slides/mongodb/sharding-horizontal-scale.xml</slide>
<slide>slides/mongodb/sharding-data-store-old.xml</slide>
<slide>slides/mongodb/sharding-why.xml</slide>
<slide>slides/mongodb/sharding-working-set.xml</slide>
<slide>slides/mongodb/sharding-throughput.xml</slide>
<slide>slides/mongodb/sharding-mongo-approach.xml</slide>
<slide>slides/mongodb/sharding-partition.xml</slide>
<slide>slides/mongodb/sharding-chunks.xml</slide>
<slide>slides/mongodb/sharding-manages.xml</slide>
<slide>slides/mongodb/sharding-auto-shard.xml</slide>
<slide>slides/mongodb/sharding-architecture.xml</slide>
<slide>slides/mongodb/sharding-shard.xml</slide>
<slide>slides/mongodb/sharding-config-server.xml</slide>
<slide>slides/mongodb/sharding-mongos-manages.xml</slide>
<slide>slides/mongodb/sharding-infrastructure.xml</slide>
<!--
<slide>slides/mongodb/sharding-configuration.xml</slide>
<slide>slides/mongodb/sharding-example-setup.xml</slide>
<slide>slides/mongodb/sharding-start-config.xml</slide>
<slide>slides/mongodb/sharding-start-mongos.xml</slide>
<slide>slides/mongodb/sharding-start-db.xml</slide>
<slide>slides/mongodb/sharding-add-shard.xml</slide>
<slide>slides/mongodb/sharding-verify-added.xml</slide>
<slide>slides/mongodb/sharding-enable.xml</slide>
-->
<slide>slides/mongodb/sharding-key-title.xml</slide>
<slide>slides/mongodb/sharding-shard-key.xml</slide>
<slide>slides/mongodb/sharding-key-considerations.xml</slide>
- hashed shard keys can help with the 512-byte size limitation
<slide>slides/mongodb/sharding-key-example.xml</slide>
<slide>slides/mongodb/sharding-key-example2.xml</slide>
<slide>slides/mongodb/sharding-connecting.xml</slide>
<slide>slides/mongodb/sharding-mechanics.xml</slide>
<slide>slides/mongodb/sharding-partitioning.xml</slide>
<slide>slides/mongodb/sharding-chunk-is-range.xml</slide>
<slide>slides/mongodb/sharding-chunk-splitting.xml</slide>
<slide>slides/mongodb/sharding-balancing.xml</slide>
<!--
<slide>slides/mongodb/sharding-acquire-lock.xml</slide>
<slide>slides/mongodb/sharding-move-chunk.xml</slide>
<slide>slides/mongodb/sharding-commit-migration.xml</slide>
<slide>slides/mongodb/sharding-cleanup.xml</slide>
-->
<slide>slides/mongodb/sharding-balancing-tips.xml</slide>
<slide>slides/mongodb/sharding-routing.xml</slide>
<slide>slides/mongodb/sharding-routing-types.xml</slide>
<slide>slides/mongodb/sharding-targeted-query.xml</slide>
<slide>slides/mongodb/sharding-targeted-query1.xml</slide>
<slide>slides/mongodb/sharding-targeted-query2.xml</slide>
<slide>slides/mongodb/sharding-targeted-query3.xml</slide>
<slide>slides/mongodb/sharding-targeted-query4.xml</slide>
<slide>slides/mongodb/sharding-non-targeted-query.xml</slide>
<slide>slides/mongodb/sharding-non-targeted-query1.xml</slide>
<slide>slides/mongodb/sharding-non-targeted-query2.xml</slide>
<slide>slides/mongodb/sharding-non-targeted-query3.xml</slide>
<slide>slides/mongodb/sharding-non-targeted-query4.xml</slide>
<slide>slides/mongodb/sharding-non-targeted-with-sort-query.xml</slide>
<slide>slides/mongodb/sharding-non-targeted-with-sort-query1.xml</slide>
<slide>slides/mongodb/sharding-non-targeted-with-sort-query2.xml</slide>
<slide>slides/mongodb/sharding-non-targeted-with-sort-query3.xml</slide>
<slide>slides/mongodb/sharding-non-targeted-with-sort-query4.xml</slide>
<slide>slides/mongodb/sharding-non-targeted-with-sort-query5.xml</slide>
<slide>slides/mongodb/sharding-non-targeted-with-sort-query6.xml</slide>
<!--
<slide>slides/mongodb/sharding-geo-aware.xml</slide>
<slide>slides/mongodb/sharding-add-tag.xml</slide>
<slide>slides/mongodb/sharding-tag-shard-range.xml</slide>
-->
<slide>slides/mongodb/atlas.xml</slide>
<slide>slides/mongodb/questions.xml</slide>
<slide>slides/mongodb/resources.xml</slide>
</presentation>

View File

@@ -2,6 +2,8 @@
<title>Connection String</title>
<example result="0"><![CDATA[<?php
require 'vendor/autoload.php';
$options = [ 'replicaSet' => 'seta' ];
$m = new \MongoDB\Client( 'mongodb://localhost:13000/?replicaSet=seta' );

View File

@@ -1,17 +1,18 @@
<slide>
<title>Read preferences</title>
<title>Read Preference</title>
<subtitle>%\MongoDB\Driver\ReadPreference%</subtitle>
<example result="0"><![CDATA[<?php
$m = new \Mongo\Driver\Manager(
$m = new \MongoDB\Client(
'mongodb://localhost:13000/?replicaSet=poiset' .
'&readPreference=nearest&readPreferenceTags=dc:asia'
);
$m->executeQuery( 'demo.test', $query );
$m->demo->test->find( $query );
?>]]></example>
<blurb>or per-query:</blurb>
<example result="0"><![CDATA[<?php
$m = new \Mongo\Driver\Manager(
$m = new \MongoDB\Client(
'mongodb://localhost:13000/?replicaSet=poiset'
);
@@ -19,7 +20,7 @@ $rp = new MongoDB\Driver\ReadPreference(
MongoDB\Driver\ReadPreference::RP_NEAREST, [ [ 'dc' => 'asia' ] ]
);
$m->executeQuery( 'demo.test', $query, $rp );
$m->demo->test->find( $query, [ 'readPreference' => $rp ] );
?>]]></example>
</slide>

View File

@@ -1,13 +1,14 @@
<slide>
<title>Read preferences</title>
<title>Read Preference</title>
<subtitle>%\MongoDB\Driver\ReadPreference%</subtitle>
<blurb>Select between candidate servers from a specific set</blurb>
<list>
<bullet>primary (default)</bullet>
<bullet>primary_preferred (%RP_PRIMARY_PREFERRED%)</bullet>
<bullet>secondary</bullet>
<bullet>secondary_preferred</bullet>
<bullet>nearest</bullet>
<bullet>%RP_PRIMARY% (default)</bullet>
<bullet>%RP_PRIMARY_PREFERRED%</bullet>
<bullet>%RP_SECONDARY%</bullet>
<bullet>%RP_SECONDARY_PREFERRED%</bullet>
<bullet>%RP_NEAREST%</bullet>
</list>
<break/>
<list>

View File

@@ -1,8 +1,8 @@
<slide>
<title>Eventual consistency</title>
<title>Eventual Consistency</title>
<list>
<bullet>Read Preferences (except %RP_PRIMARY%)
<bullet>Read Preference (except %RP_PRIMARY%)
<list>
<bullet>Driver will always send writes to primary</bullet>
<bullet>Driver will send read requests to secondaries</bullet>
@@ -14,7 +14,6 @@
<list>
<bullet>Secondaries may be out of date</bullet>
<bullet>Failover may happen while you're trying to write</bullet>
<bullet>Not appropriate for all applications</bullet>
</list>
</bullet>
</list>

View File

@@ -2,11 +2,11 @@
<title>MongoDB Replica Set Features</title>
<list>
<bullet>A cluster of N servers</bullet>
<bullet>All writes to primary</bullet>
<bullet>A cluster of *~n~* servers</bullet>
<bullet>All writes to *primary*</bullet>
<bullet>Reads can be from primary (default) or a secondary</bullet>
<bullet>Any (one) node can be primary</bullet>
<bullet>Consensus election of primary</bullet>
<bullet>Any *(one)* node can be primary</bullet>
<bullet>Consensus *election* of primary</bullet>
<bullet>Automatic failover and recovery</bullet>
</list>
</slide>

View File

@@ -0,0 +1,21 @@
<slide>
<title>Read Concern</title>
<subtitle>%\MongoDB\Driver\ReadConcern%</subtitle>
<list>
<bullet>%local%: No guarantees</bullet>
<bullet>%available%: No guarantees</bullet>
<bullet>%majority%: Returns data acknowledged by a majority of the nodes</bullet>
<bullet>%lineralizable%: Returns data acknowledged by a majority of the nodes, completed before the start of the read operation</bullet>
</list>
<example result="0"><![CDATA[<?php
$m = new \MongoDB\Client(
'mongodb://localhost:13000/?replicaSet=poiset'
);
$rc = new MongoDB\Driver\ReadConcern( MongoDB\Driver\ReadConcern::LINEARIZABLE );
$m->demo->test->find( $query, [ 'readConcern' => $rc, 'maxTimeMS' => 200 ] );
?>]]></example>
</slide>

View File

@@ -4,7 +4,7 @@
<table>
<tr><th>Use</th><th>Set size</th><th>Data protection</th><th>High Availability</th><th>Notes</th></tr>
<tr><td> </td><td>1</td><td>No </td><td>No</td><td>Must use --journal to protect against crashes</td></tr>
<tr><td>|008800|✔|</td><td>2</td><td>Yes</td><td>No</td><td>On loss of one member, set becomes read-only</td></tr>
<tr><td> </td><td>2</td><td>Yes</td><td>No</td><td>On loss of one member, set becomes read-only</td></tr>
<tr><td>|008800|✔|</td><td>3</td><td>Yes</td><td>Yes - 1 failure</td><td>On loss of one member, two surviving nodes can elect new primary</td></tr>
<tr><td> </td><td>4</td><td>Yes</td><td>Yes - 1 failure</td><td>On loss of two members, two surviving nodes are read-only</td></tr>
<tr><td>|008800|✔|</td><td>5</td><td>Yes</td><td>Yes - 2 failures</td><td>On loss of two members, three surviving nodes can elect new primary</td></tr>

View File

@@ -1,20 +1,20 @@
<slide>
<title>Write concerns</title>
<example><![CDATA[<?php
$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017');
$bulk = new MongoDB\Driver\BulkWrite();
$bulk->insert(['_id' => 1, 'x' => 1]);
$result = $manager->executeBulkWrite( 'db.collection', $bulk, $wc );
]]></example>
<title>Write Concern</title>
<subtitle>%\MongoDB\Driver\WriteConcern%</subtitle>
<list>
<bullet>Two nodes:<br/><example>$wc = new MongoDB\Driver\WriteConcern( 2 );</example></bullet>
<bullet>Majority of nodes:<br/><example>$wc = new MongoDB\Driver\WriteConcern( MongoDB\Driver\WriteConcern::MAJORITY );</example></bullet>
<bullet>With timeout:<br/><example>$wc = new MongoDB\Driver\WriteConcern(
MongoDB\Driver\WriteConcern::MAJORITY, 10000
);</example></bullet>
<bullet>Majority of nodes:<br/><example>$wc = new MongoDB\Driver\WriteConcern( MongoDB\Driver\WriteConcern::MAJORITY );</example></bullet>
<bullet>With timeout:<br/><example>$wc = new MongoDB\Driver\WriteConcern( MongoDB\Driver\WriteConcern::MAJORITY, 10000 );</example></bullet>
</list>
<example><![CDATA[<?php
require 'vendor/autoload.php';
$con = new \MongoDB\Client('mongodb://localhost:27017');
$res = $con->db->collection->insertOne(
[ '_id' => 1, 'x' => 1 ],
[ 'writeConcern' => $wc ],
);
]]></example>
</slide>

View File

@@ -0,0 +1,26 @@
<slide>
<title>Write Some Code</title>
<blurb>Write a script that:</blurb>
<list>
<bullet>Connects to the Replica Set</bullet>
<bullet>Inserts a Document</bullet>
<bullet>Reads Document from Secondary</bullet>
</list>
<break/>
<example>
mkdir new-project
cd new-project
composer require mongodb/mongodb
</example>
<example><![CDATA[<?php
require 'vendor/autoload.php';
$client = new \Mongo\Client( $dsn );
$collection = $client->selectCollection( 'databasename', 'collectionname' );
?>]]></example>
<break/>
<blurb>See slides: ~9~, ~22~, ~28~</blurb>
</slide>

View File

@@ -1,38 +1,28 @@
<slide>
<title>Setting up replication</title>
<title>Setting up Replication</title>
<blurb>Open three terminals, and create three directories: %db1%, %db2% and %arb%</blurb>
<blurb>Starting the daemons (2 data, 1 arbiter):</blurb>
<example>
mongod -f /etc/mongodb.conf --dbpath=~/repl-slave0 --port 13000 --replSet seta
mongod -f /etc/mongodb.conf --dbpath=~/repl-slave1 --port 13001 --replSet seta
mongod -f /etc/mongodb.conf --dbpath=~/repl-arb --port 13002 --replSet seta --rest
mongod --dbpath=./db1 --port 13000 --replSet seta --smallfiles --logpath=db1.log
mongod --dbpath=./db2 --port 13001 --replSet seta --smallfiles --logpath=db2.log
mongod --dbpath=./arb --port 13002 --replSet seta --smallfiles --logpath=arb.log
</example>
<div effect="fade-out">
<blurb>Sample %/etc/mongodb.conf%</blurb>
<example>
logpath=/var/log/mongodb/mongodb.log
logappend=true
smallfiles=true
</example>
</div>
<div effect="fade-in">
<blurb>Configure the set:</blurb>
<example>
mongo whisky:13000
$ mongo localhost:13000
> db.adminCommand( {
replSetInitiate: {
_id: 'seta',
members: [
{ _id: 0, host: 'whisky:13000', tags: { 'dc': 'west', 'use': 'accounting' } },
{ _id: 1, host: 'whisky:13001', tags: { 'dc': 'east', 'use': 'reporting' } },
]
}
} );
PRIMARY> rs.addArb('whisky:13002');
> rs.initiate( { _id: 'seta', members: [ { _id: 0, host: 'localhost:13000' } ] } );
seta:PRIMARY> rs.add('localhost:13001');
seta:PRIMARY> rs.addArb('localhost:13002');
</example>
</div>
<blurb>Check whether it worked:</blurb>
<example>
seta:PRIMARY> db.isMaster();
seta:PRIMARY> rs.status();
</example>
</slide>

View File

@@ -2,17 +2,8 @@
<title>Data Store Scalability Today</title>
<list>
<bullet>
MongoDB auto-sharding available
</bullet>
<bullet>
A data store that is
<list>
<bullet>Free and publicly available</bullet>
<bullet>Open source (https://github.com/mongodb/mongo)</bullet>
<bullet>Horizontally scalable</bullet>
<bullet>Application independent</bullet>
</list>
</bullet>
<bullet>MongoDB has auto-sharding</bullet>
<bullet>Horizontally scalable</bullet>
<bullet>Application independent</bullet>
</list>
</slide>

View File

@@ -3,7 +3,7 @@
<list>
<bullet>Shard is a node of the cluster</bullet>
<bullet>Shard can be a single mongod or a replica set</bullet>
<bullet>Shard can be ---a single mongod or--- a replica set</bullet>
</list>
<break lines="3"/>

73
xdebug-tek18.xml Normal file
View File

@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<presentation css="10gen-strict.css">
<topic>Debugging</topic>
<title>What's New in Xdebug</title>
<event>php[tek] 2018</event>
<location>Atlanta, GA, USA</location>
<date>June 1st, 2018</date>
<speaker>Derick Rethans</speaker>
<email>derick@xdebug.org</email>
<twitter>derickr</twitter>
<url>http://derickrethans.nl/talks.html</url>
<joindin>https://joind.in/23137</joindin>
<slide>slides/mongodb/title.xml</slide>
<slide>slides/mongodb/me.xml</slide>
<slide>slides/xdebug/xdebug-var-dump.xml</slide>
<slide>slides/xdebug/shutup.xml</slide>
<slide>slides/xdebug/tracing.xml</slide>
<slide>slides/xdebug/functiontrace-summary.xml</slide>
<slide>slides/xdebug/xdebug-2.3-error-munging.xml</slide>
<slide>slides/xdebug/analyse-running-script.xml</slide>
<slide>slides/xdebug/xdebug-2.3-new.xml</slide>
<slide>slides/xdebug/xdebug-2.6-new-dbgp.xml</slide>
<slide>slides/xdebug/debugger-activation.xml</slide>
<slide>slides/xdebug/debugger-browser-extensions.xml</slide>
<slide>slides/xdebug/phpstorm.xml</slide>
<slide>slides/xdebug/debugger-connection-log.xml</slide>
<slide>slides/xdebug/live-demo.xml</slide>
<slide>slides/xdebug/profile2.xml</slide>
<slide>slides/xdebug/profiling.xml</slide>
<slide>slides/xdebug/profiling2.xml</slide>
<slide>slides/xdebug/live-demo.xml</slide>
<slide>slides/xdebug/paths.xml</slide>
<slide>slides/xdebug/vld-path-4-code.xml</slide>
<slide>slides/xdebug/vld-path-4-output.xml</slide>
<slide>slides/xdebug/vld-path-3-code.xml</slide>
<slide>slides/xdebug/vld-path-3-output.xml</slide>
<slide>slides/xdebug/vld-path-3-paths.xml</slide>
<slide>slides/xdebug/vld-path-5-wrapup.xml</slide>
<slide>slides/xdebug/xdebug-2.4-new.xml</slide>
<slide>slides/xdebug/function-monitor.xml</slide>
<slide>slides/xdebug/xdebug-2.5-new.xml</slide>
<slide>slides/xdebug/happy-15th.xml</slide>
<slide>slides/xdebug/xdebug-2.6-new.xml</slide>
<slide>slides/xdebug/xdebug-2.6-switch.xml</slide>
<slide>slides/xdebug/xdebug-2.6-switch2.xml</slide>
<slide>slides/xdebug/xdebug-2.6-switch3.xml</slide>
<slide>slides/xdebug/xdebug-2.6-filter1.xml</slide>
<slide>slides/xdebug/xdebug-2.6-filter1a.xml</slide>
<slide>slides/xdebug/xdebug-2.6-filter1b.xml</slide>
<slide>slides/xdebug/xdebug-2.6-filter2.xml</slide>
<slide>slides/xdebug/xdebug-2.6-filter2a.xml</slide>
<slide>slides/xdebug/donate.xml</slide>
<slide>slides/xdebug/resources.xml</slide>
</presentation>