Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Wykorzystanie klastra Apache Mesos w deploymencie aplikacji pythonowych

Wykorzystanie klastra Apache Mesos w deploymencie aplikacji pythonowych

Kamil Warguła

November 29, 2015
Tweet

Other Decks in Technology

Transcript

  1. 2

  2. What is Mesos? Apache Mesos abstracts CPU, memory, storage, and

    other compute resources away from machines (physical or virtual), enabling fault-tolerant and elastic distributed systems to easily be built and run effectively. 4
  3. Mesos architecture Mesos master Standby master Standby master ZooKeeper quorum

    Mesos slave Framework executor task Mesos slave Framework executor task Mesos slave Marathon executor task Hadoop executor task Framework scheduler 5
  4. Marathon features • Web UI • JSON/REST API • HA

    • Constraints • Health Checks • Event Subscription • Basic Auth and SSL 11
  5. simple python REST app import falcon import json class ExampleResource:

    def on_get(self, req, resp): data = {'foo': 'bar'} resp.body = json.dumps(data) api = falcon.API() api.add_route('/', ExampleResource()) 15
  6. integration with gunicorn from gunicorn.app.base import BaseApplication class StandaloneApplication(BaseApplication): ...

    def _get_config(): ... def main(): api = falcon.API() api.add_route('/', Example Resource()) config = _get_config() StandaloneApplication(api, config).run() if __name__ == '__main__': main() 16
  7. Marathon app definition { "id": "appname", "cmd": "python my_app.py", "cpus":

    0.5, "instances": 1, "mem": 64, "uris": [ "http://artifacts.local/my_app_0.1.0.tar.gz" ] } 22
  8. Scale app - manual import json import requests url =

    'http://marathon.local/v2/apps/myapp' data = {'instances': 5} requests.put(url, data=json.dumps(data)) 27
  9. Autoscale app MIN_INSTANCES_COUNT = 2 MAX_INSTANCES_COUNT = 20 if overloaded_instances

    >= 0.9 * total_instances: total_instances += 2 if total_instances <= MAX_INSTANCES_COUNT: scale_app(total_instances) elif overloaded_instances <= 0.5 * total_instances: total_instances -= 2 if total_instances >= MIN_INSTANCES_COUNT: scale_app(total_instances) 29