Locomotor Transparent Migration of Client-Side Database Code - - PowerPoint PPT Presentation

locomotor transparent migration of client side database
SMART_READER_LITE
LIVE PREVIEW

Locomotor Transparent Migration of Client-Side Database Code - - PowerPoint PPT Presentation

Locomotor Transparent Migration of Client-Side Database Code Michael Mior University of Waterloo Complex database operations often require queries and updates to be mixed with application code Stored Procedures Using stored


slide-1
SLIDE 1

Locomotor Transparent Migration of Client-Side Database Code

Michael Mior – University of Waterloo

slide-2
SLIDE 2

Stored Procedures ▸ Complex database operations often require queries and updates to be mixed with application code ▸ Using stored procedures can reduce latency by cutting back on round trips

slide-3
SLIDE 3

Stored Procedures ▸ Server-side scripting languages differ from the language used to develop the application ▸ Independent maintenance is required ▸ Required data needs to be carefully transferred in both directions

slide-4
SLIDE 4

Locomotor ▸ Automatically convert annotated Python functions into server-side Lua scripts in Redis ▸ Patch the Python code at runtime to call the dynamically-generated script ▸ Updated code is automatically re-translated and deployed

slide-5
SLIDE 5

Shipping Example Redis Data Model Key-value store where values can be complex types (e.g. maps, lists)

item:1 → { name: 'Foo', category: 'Bar' } category:Bar → ['item:1', …]

slide-6
SLIDE 6

Shipping Example Application Code

hmset('item:' + str(key), {'name': 'Foo'}) lpush('category:Books', 'item:1') ids = lrange('category:' + category, 0, -1) items = [] for id in ids: items.append(hget(id, 'name')) return items

slide-7
SLIDE 7

Shipping Example Application Code

hmset('item:' + str(key), {'name': 'Foo'}) lpush('category:Books', 'item:1') ids = lrange('category:' + category, 0, -1) items = [] for id in ids: items.append(hget(id, 'name')) return items

Each of these calls requires a round trip to the server! And once per iteration

hmset lpush lrange for id in ids: hget

slide-8
SLIDE 8

Shipping Example Server Script

local category = 'category:' .. ARGV[1] local item_keys = redis.call('lrange', 'category:' .. category, 0, -1) local items = {} for _, key in ipairs(item_keys) do table.insert(items, redis.call('hget', key, 'name')) end return items

slide-9
SLIDE 9

Shipping Example Server Script

local category = 'category:' .. ARGV[1] local item_keys = redis.call('lrange', 'category:' .. category, 0, -1) local items = {} for _, key in ipairs(item_keys) do table.insert(items, redis.call('hget', key, 'name')) end return items

Only one round trip needed

slide-10
SLIDE 10

Auto Translate

  • 1. Data type conversions
  • 2. Differing language semantics
  • 3. Built-in functions
  • 4. Loop constructs

slide-11
SLIDE 11

Deploy Each time an annotated function is run, it is translated/shipped on the fly

@redis_server def get_category(redis, cat): ...

slide-12
SLIDE 12

Evaluation

Client

slide-13
SLIDE 13

Evaluation

  • Shipping code reduced round trips

from 24 to 8

  • With an inefficient server-side

implementation, we still achieve a 4× reduction in runtime

slide-14
SLIDE 14

Summary ▸ Translation of client code to server-side scripting languages is a viable approach to optimization ▸ This optimization can be automated with careful observation of language semantics

slide-15
SLIDE 15

Future Work ▸ Explore other DB/language combos such as MongoDB and JavaScript ▸ Automated selection of code fragments to translate and move ▸ Use of low-level interfaces (e.g. Redis modules)

slide-16
SLIDE 16

Questions?