-
Notifications
You must be signed in to change notification settings - Fork 0
Elliptics server side applications tutorial
This tutorial is intended to cover the gap in the reverbrain elliptics documentation in server side data processing topic which is outdated and incomplete.
To proceed with this tutorial you should have elliptics installed, and get some idea how to configure and operate it.
You also will need following packages installed:
- elliptics
- elliptics-client
- cocaine-tools
- libcocaine-plugin-elliptics
- cocaine-framework-python
- cocaine-framework-native
Elliptics has a mechanism to run apps on it's nodes intended for processing data put into storage, app engine is event driven and provide mechanism to run data processing apps locally to the data. App engine is a layer on top of Cocaine, and provides own protocol for managing apps and messages. Attempts to mix Cocaine and elliptics app management lead to Elliptics crashes. [TODO: check that this is true] Each app[TODO: or even app instance?] uses its own Cocaine instance, so you won't get any Cocaine balansing capabilities.
Already configured elliptics should have one additional parameter in it's configuration file
"srw_config": "/etc/elliptics/srw.json"
this is a link to the Cocaine config. Click for full sample config file.
Note that all directories mentioned in the config must be created before launchig Elliptics.
To run elliptics with this config files put them to /etc/elliptics and run command
dnet_ioserv -c /etc/elliptics/ioserv_srw.json[TODO: I totally omit if it should run as root or own user, have to investigate]
Full sample config is under the link, lets go though it in some details.
Services section defines what services will be used in Cocaine layer
"services": {
"logging": {
"type": "logging",
"args": {
"port": 12501
}
},
"storage": {
"type": "elliptics"
}
}logging service and storage service are mandatory, storage should be set to elliptics, uploaded apps would be stored there[TODO: how change to file storage affect app distribution to nodes in case of elliptics managed Cocaine? in standalone Cocaine app will be upploaded to current node only].
[TODO: residual from experiments, probably should be thrown away]
"node": {
"type": "node",
"args": {
"runlist": "default"
}
}Storages section sets parameters for elliptics storage, list of nodes to connect, set of groups and logging verbosity
"storages": {
"core": {
"type": "elliptics",
"args": {
"nodes": ["localhost:1025:2"],
"groups": [1],
"verbosity": 2[TODO: is it still a number or word should be used?]
}
}
}I prepared a mighty script that gets all initialization done and runs elliptics service as a reference
Note the commented line
dd bs=64 count=10 if=/dev/urandom of=/elliptics/history/idsIt creates 10 random ranges, you can use it if you don't like how elliptics create ranges by default.
The minimal python application
#!/usr/bin/env python
from cocaine.worker import Worker
def test_event(request, response):
response.close()
W = Worker()
W.run({"test_event" : test_event})This app creates a worker instance and registers a hander for "test_event" which just does nothing. To upload this app to the elliptics you should issue commands:
tar -cf test_app.tar test_app.py
cocaine-tool app upload --manifest test_app_manifest.json --package test_app.tar --name test_app
cocaine-tool profile upload --profile process_isolate.profile --name test_app
dnet_ioclient -r localhost:1025:2 -g 1 -c "test_app@start-task"you can test that app is working by calling
dnet_ioclient -r localhost:1025:2 -g 1 -c "test_app@test_event"it should show acknowledge answer from each node, if you want to run app on the node with specific key call
dnet_ioclient -r localhost:1025:2 -g 1 -c "test_app@test_event key_string"it should show acknowledge from the node with the key.
[TODO: add sending events from python and cpp code.]
You also can run app using cocaine mechanism instead of elliptics events, in that case you should change the way events are registered[TODO: this thing with handlers bugs me alot]
W = Worker()
W.run({"test_app@test_event" : test_event})Sample code to run app:
from cocaine.services import Service
app = Service("test_app")
for i in app.enqueue("test_app@test_event", "Hello\n"):
print iquestions:
how apps and profiles are matched when elliptics server side processing is used?
how to write responses in python?
how to create event handlers that can be called from both cocaine interface and through elliptics messaging?