Slide 1

Slide 1 text

M a r i u s z G i l P H P

Slide 2

Slide 2 text

about me

Slide 3

Slide 3 text

frontend application cache data store

Slide 4

Slide 4 text

data store

Slide 5

Slide 5 text

data store scaling is hard

Slide 6

Slide 6 text

SQL way denormalization / partitioning / sharding

Slide 7

Slide 7 text

id username attribute_1 attribute_2 1 atermida 1 5 2 saturn 3 2 3 zeus 3 7 … … … …

Slide 8

Slide 8 text

id username attribute_1 attribute_2 1 atermida 1 2 saturn 2 3 zeus 3 7 … … … … attribute_n 9 …

Slide 9

Slide 9 text

id username 1 atermida 2 saturn 3 zeus … … user_id attribute_id value 1 342 1 2 342 2 3 343 3 … … … user_id attribute_id value 1 348 abc 2 348 abd 3 900 eee … … …

Slide 10

Slide 10 text

noSQL way scalability / consistency / availability / partitioning

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

namespaces sets records bins

Slide 15

Slide 15 text

nodes clusters namespaces sets

Slide 16

Slide 16 text

id username attr_1 attr_2 attr_3 1 atermida 1 2 saturn 2 3 zeus [1, 3, 4] … … … … …

Slide 17

Slide 17 text

simple and complex data types

Slide 18

Slide 18 text

aql> insert into test.users (PK, username, attr_1) values ('atena', 'atena', 1); OK, 1 record affected. aql> insert into test.users (PK, username, attr_2) values ('zeus', 'zeus', 2); OK, 1 record affected. aql> insert into test.users (PK, username, attr_3) values ('saturn', 'saturn', 'JSON{"account": "silver", "balance":0}'); OK, 1 record affected. aql> select * from test.users +----------+--------+--------+-----------------------------------+ | username | attr_2 | attr_1 | attr_3 | +----------+--------+--------+-----------------------------------+ | "zeus" | 2 | | | | "atena" | | 1 | | | "saturn" | | | {"account":"silver", "balance":0} | +----------+--------+--------+-----------------------------------+ 3 rows in set (0.375 secs) aql> select * from test.users where PK='atena' +----------+--------+ | username | attr_1 | +----------+--------+ | "atena" | 1 | +----------+--------+ 1 row in set (0.000 secs)

Slide 19

Slide 19 text

record and stream Lua UDFs

Slide 20

Slide 20 text

aql> execute list.push('mylist', 'a') on test.demo where PK = '1' +------+ | push | +------+ | 1 | +------+ 1 row in set (0.000 secs) aql> execute list.push('mylist', 'b') on test.demo where PK = '1' +------+ | push | +------+ | 2 | +------+ 1 row in set (0.000 secs) aql> execute list.push('mylist', 'c') on test.demo where PK = '1' +------+ | push | +------+ | 3 | +------+ 1 row in set (0.000 secs) aql> execute list.peek('mylist', 3) on test.demo where PK = '1' +--------------------------+ | peek | +--------------------------+ | ["c", "b", "a"] | +--------------------------+ 1 row in set (0.000 secs)

Slide 21

Slide 21 text

PHP way native client

Slide 22

Slide 22 text

installation # Install dependencies sudo apt-get install build-essential autoconf libssl-dev sudo apt-get install php5-dev php-pear # Build extension composer require aerospike/aerospike-client-php "*" find vendor/aerospike/aerospike-client-php/ -name "*.sh" -exec chmod +x {} \; cd vendor/aerospike/aerospike-client-php/ && composer run-script post-install-cmd # Create ini file extension=aerospike.so aerospike.udf.lua_system_path=/path/to/client-php/sys-lua aerospike.udf.lua_user_path=/path/to/client-php/usr-lua

Slide 23

Slide 23 text

$config = [ "hosts" => [ ["addr" => "127.0.0.1", "port" => 3000] ] ]; $db = new Aerospike($config); $key = $db->initKey("infosphere", "characters", 1234); $db->put($key, ["name" => "Scruffy", "Occupation" => "The Janitor"]); $db->put($key, [ "quotes" => [ "I'm Scruffy. The janitor.", "I'm on break.", "Scruffy's gonna die like he lived.", ] ]); $db->get($key, $record, ["name", "quotes"]); $db->close(); simple flow

Slide 24

Slide 24 text

$db->scan("infosphere", "characters", function ($record) { var_dump($record); }, ["name"]); $where = Aerospike::predicateBetween("age", 30, 39); $status = $db->query("infosphere", "characters", $where, function ($record) { var_dump($record); }, ["name", "age"]); scans and queries

Slide 25

Slide 25 text

$status = $db->register('/path/to/my_udf.lua', 'my_udf'); $key = $db->initKey('test', 'demo', 'foo'); $db->apply($key, "sample", "list_append", ["things", "!!!"]); $status = $db->scanApply("test", "users", "rec_udf", "accumulate", ["balance", "income"], $scan_id); $where = Aerospike::predicateBetween("age", 20, 29); $status = $db->aggregate("test", "users", $where, "mymod", "group_count", ["first_name"], $names); user definied functions

Slide 26

Slide 26 text

$key = $db->initKey("test", "shows", "Futurama"); $db->put($key, [ "creator" => ["Matt Groening", "David X Cohen"], "broadcast" => [[1999,2003], [2008,2013]], ]); $characters = new \Aerospike\LDT\LSet($db, $key, 'characters'); $characters->add('Professor Hubert J. Farnsworth'); $characters->addMany([ "Amy Wong", "Hermes Conrad", "Dr. John A. Zoidberg", "Tarunga Leela", "Philip J. Fry", "Bender Bending Rodriguez", "Scruffy", "Cubert Farnsworth” ]); large data types

Slide 27

Slide 27 text

use cases

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

Don’t trust instead, do your own benchmarks in your env

Slide 31

Slide 31 text

Thanks! @mariuszgil