In [1]:
from kitchensink import setup_client, client
from kitchensink import do, dp, du
from kitchensink import settings
from kitchensink.admin import timethis
setup_client('http://localhost:6323/')
c = client()
In [2]:
def add(x, y):
return x + y
c.cs(add, 1, 2)
Out[2]:
Here - cs is short for call_single, execute a single function remotely, and return the result
In [3]:
def double(x):
return 2 * x
c.map(double, [1,2,3,4,5])
Out[3]:
We also have a map function, duplicating the builtin map, but the function you pass into map needs to take one parameter. The most flexible pattern for using kitchensink, is to use bc (bulk_call), execute, and the br (bulk_results)
In [4]:
for counter in range(10):
c.bc(add, 1, 2)
c.execute()
c.br()
Out[4]:
bc - queues up a function for execution(locally), execute sends all the function calls to the server, br, pulls down the results
In [5]:
import time
def long_running_computation_with_some_progress_output():
print 'starting'
time.sleep(1)
print 'finished step1'
time.sleep(1)
print 'done'
c.cs(long_running_computation_with_some_progress_output)
In [6]:
c.cs(add, "some string", 1)
In [10]:
from kitchensink.admin import timethis
def dummy_slow_function():
print settings.rpc_url
time.sleep(1)
with timethis('slow'):
dummy_slow_function()
dummy_slow_function()
In [11]:
with timethis('parallel'):
for counter in range(4):
c.bc(dummy_slow_function)
c.execute()
c.br()
In [12]:
c.hosts()
Out[12]:
In [13]:
import numpy as np
import pandas as pd
size = 1000000
dummy_data1 = pd.DataFrame({'a' : np.random.random(size), 'b' : np.random.random(size)})
dummy_data2 = pd.DataFrame({'a' : np.random.random(size), 'b' : np.random.random(size)})
from kitchensink import do, dp, du
c.reducetree('*')
obj1 = do(dummy_data1)
obj1.rpc_url = 'http://localhost:6323/'
obj1.save(url='dummy1')
obj2 = do(dummy_data2)
obj2.rpc_url = 'http://localhost:6234/'
obj2.save(url='dummy2')
In [14]:
c.path_search('*')
Out[14]:
In [15]:
c.data_info(['dummy1', 'dummy2'])
Out[15]:
In [32]:
def calc_sum(obj):
with timethis('extracting df'):
df = obj.obj()
print settings.rpc_url, obj.data_url
with timethis('sum'):
return df.sum()
c.bc(calc_sum, du('dummy1'))
c.bc(calc_sum, du('dummy2'))
c.execute()
c.br()
Out[32]:
In [36]:
c.bc(calc_sum, du('dummy1'), _no_route_data=True)
c.bc(calc_sum, du('dummy2'), _no_route_data=True)
c.execute()
c.br()
Out[36]:
In [37]:
c.bc(calc_sum, du('dummy1'))
c.bc(calc_sum, du('dummy2'))
c.execute()
c.br(profile='sum')
Out[37]:
In [ ]: