`
m635674608
  • 浏览: 5004987 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

marathon-autoscaling功能研究

 
阅读更多

1.概述:

目前marathon主要支持两种autoscaling:1.基于cpu、内存使用率的autoscaling;2.基于服务请求频率的autoscaling。下面将就这两种autoscaling的原理和用法进行详述。

2.基于CPU和内存使用率的autoscaling

2.1原理

app autoscaling的实现主要依靠一个运行在主机上名为marathon-autoscale.py的Python脚本,不断监测app中cpu和内存的使用率,当使用率达到阈值时自动扩展app中instance的数量。这个脚本启动时主要配置好几个参数:Marathon的地址、要监测并自动扩展的app名字、这个app所有instance中平均内存使用率的上限、这个app所有instance中平均CPU使用率的上限、自动扩展的Instance数量的上限。

通过看脚本的代码可以看到脚本中有一个marathon的class,通过传入marathon的url来初始化它,如下图所示:

 

在main函数中可以看到使用marathon类创建了一个aws_marathon的对象,然后调用这个对象的get_app_detail函数返回一个所有APP的task和所在host的信息。之后主要就是通过这个两个信息来调用get_task_agentstatistics(task,host)函数从http://'+host +':5051/monitor/statistics.json获取每个instance上cpu和内存的使用情况。

以上分析得出结论,其实最终是调用mesos的监控机制,从mesos-slave上获取app中各instance上cpu和内存的使用率的。想了解Mesos的monitoring机制请看:http://mesos.apache.org/documentation/latest/monitoring/

 

 

2.2使用

1.创建app

on 10.134.29.141

•        1.编辑.json文件

vim nginx-autoscaling.json

{

  "id": "nginx-autoscaling”,

  "Container": {

    "type": "Docker",

    "docker": {

      "image":"10.133.19.25:5000/library/nginx:latest",

      "network": "BRIDGE",

      "portMappings": [

        { "hostPort": 0,"containerPort": 80, "servicePort": 10002 }

      ],

      "forcePullImage":true

    }

  },

  "instances": 1,

  "cpus": 0.1,

  "mem": 65,

  "healthChecks": [{

      "protocol": "HTTP",

      "path": "/",

      "portIndex": 0,

      "timeoutSeconds": 10,

      "gracePeriodSeconds": 10,

      "intervalSeconds": 2,

      "maxConsecutiveFailures": 10

  }],

  "labels":{

   "HAPROXY_GROUP":"external,internal"

  }

}

•        2.启动app

dcosmarathon app add nginx-autoscaling.json

 

2.启动autoscaleron 10.134.29.134:

•        1.获取源码

Git clonehttps://github.com/mesosphere/marathon-autoscale.git

cdmarathon-autoscale

•        2.运行autoscale脚本

pythonmarathon-autoscale.py

       Enter the DNS hostname or IP of yourMarathon Instance : 10.134.29.134

       Enter the Marathon Application Name toConfigure Autoscale for from the Marathon UI : nginx-autoscaling

       Enter the Max percent of Mem Usageaveraged across all Application Instances to trigger Autoscale (ie. 80) : 5

       Enter the Max percent of CPU Usageaveraged across all Application Instances to trigger Autoscale (ie. 80) : 5

       Enter which metric(s) to triggerAutoscale ('and', 'or') : or

       Enter Autoscale multiplier for triggeredAutoscale (ie 1.5) : 2

       Enter the Max instances that should everexist for this application (ie. 20) : 10

3.验证:

•        1.进入docker

docker exec-it fb700c6045ad /bin/bash

•        2.加压

ddif=/dev/zero of=test bs=1M count=1000

此时查看会发现多了instance

3. 基于服务请求频率的autoscaling

3.1原理

这个的原理是启动一个marathon-lb-autoscale的app来查看Haproxy监测到的对某一app的请求频率。请求频率超过阈值便自动扩展。详细了解请见:

https://docs.mesosphere.com/administration/admin-tutorials/autoscaling-with-marathon/marathon-app-for-rate-based-autoscaling/

https://mesosphere.com/blog/2015/12/13/service-discovery-and-load-balancing-with-dcos-and-marathon-lb-part-2/

 

3.2使用

1.创建测试扩展的nginx app

2.创建marathon-lb-autoscaleapp

on 10.134.29.141:

•        1.编辑app配置文件.json

vimmarathon-lb-autoscale.json

{

  "id":"marathon-lb-autoscale",

  "args":[

    "--marathon","http://10.134.29.134:8080",

    "--haproxy","http://marathon-lb.marathon.mesos:9090",

    "--target-rps", "100",

    "--apps", "nginx_10002"

  ],

  "cpus": 0.1,

  "mem": 16.0,

  "instances": 1,

  "container": {

    "type": "DOCKER",

    "docker": {

      "image":"docker.io/mesosphere/marathon-lb-autoscale",

      "network": "HOST",

      "forcePullImage": true

    }

  }

}

•        2.启动app

dcosmarathon app add marathon-lb-autoscale.json

 

3.验证

先将siege镜像用docker pull下载并上传到私有仓库中:

docker pull yokogawa/siege

docker tag docker.io/yokogawa/siege:latest10.133.19.25:5000/siege:latest

docker push10.133.19.25:5000/siege:latest(如果上传不成功的话需要上传的主机的docker启动参数加上--insecure-registry=10.133.19.25:5000)

•        1.创建一个siege app用来发送http请求进行测试:

vim siege.json

{

 "id": "siege",

 "args":[

   "-d1",

   "-r1000",

   "-c100",

   "http://10.134.29.142:10000/"

  ],

 "cpus": 0.5,

 "mem": 16.0,

 "instances": 1,

 "container": {

   "type": "DOCKER",

   "volumes": [],

   "docker": {

     "image": "10.133.19.25:5000/siege:latest",

     "network": "HOST",

     "privileged": false,

     "parameters": [],

     "forcePullImage": false

    }

  }

}

 

dcos marathon app add siege.json

•        2.加大request数量:

dcos marathon app update /siege instances=15

此时查看会发现多了nginxinstance

 

http://blog.csdn.net/liukuan73/article/details/50769790

分享到:
评论

相关推荐

    marathon-lb-1.4.3.tar.gz

    在分析`marathon-lb-1.4.3.tar.gz`这个压缩包时,我们可以深入探讨Marathon-LB的核心功能、工作原理以及如何部署和配置。 1. **Marathon-LB简介** Marathon-LB基于HAProxy,它是一个开源的高性能四层负载均衡器。...

    marathon-autoscale, 基于利用率的扩展应用在马拉松应用中的简单概念.zip

    marathon-autoscale, 基于利用率的扩展应用在马拉松应用中的简单概念 马拉松自动缩放可以在马拉松管理下运行以动态扩展运行在 dc/os上的服务的Dockerized容器 autoscaler 。先决条件正在运行的DCOS群集。如果在 dc/...

    marathon-lb:Marathon-lb是DCOS的服务发现和负载平衡工具

    马拉松磅 Marathon-lb是通过使用应用程序状态来管理HAProxy的工具。 HAProxy是一种快速,高效,经过考验的高可用性负载均衡器,具有许多高级功能,可为许多备受瞩目的网站提供支持。特征无状态设计:不直接依赖任何...

    marathon-consul, 桥马拉松信息到 Consul.zip

    marathon-consul, 桥马拉松信息到 Consul 马拉松领事 马拉松到领事桥的元数据发现。marathon-consul 获取由马拉松事件总线提供的信息并将它的转发到 consul tree 。 启动时,它还将所有来自马拉松的信息同步到 ...

    marathon-0.8.2.tgz

    这个“marathon-0.8.2.tgz”文件是一个压缩包,包含了 Marathon 的 0.8.2 版本,该版本发布于2014年左右。本文将详细讲解 Marathon 的核心功能、架构、配置以及如何部署和管理服务。 Marathon 的主要功能: 1. **高...

    Python库 | marathon-0.7.7.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:marathon-0.7.7.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    Python库 | marathon-cli-1.1.6.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:marathon-cli-1.1.6.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    Python库 | marathon-0.8.11.tar.gz

    在`marathon-0.8.11.tar.gz`这个压缩包中,包含的是`marathon`库的0.8.11版本。这个版本可能包含了该库的源代码、文档、示例以及必要的构建工具。安装和使用这个库通常需要对Python开发有一定的了解,同时也需要...

    marathon-client.py

    Python 2.7+ 用于使用marathon-client 。 安装 git clone https://github.com/Wizcorp/marathon-client.py.git cd marathon-client.py 您可以使用以下命令全局安装marathon-client.py : sudo easy_install . 或...

    marathon-ruby:Marathon 的 Ruby 客户端

    marathon-ruby是 Marathon API 的 Ruby 客户端。 到目前为止,它还没有完成,但包括启动/更新/删除应用程序的基本功能。 安装 将此行添加到应用程序的 Gemfile 中: gem 'marathon-ruby' 然后执行: $ bundle ...

    python2-marathon-0.8.7-1.el7.noarch.rpm

    官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装

    marathon-bigip-ctlr:用于Marathon的F5 BIG-IP控制器的存储库

    F5马拉松BIG-IP控制器 该GitHub存储库已归档且为只读。...官方f5networks/marathon-bigip-ctlr映像为f5networks/marathon-bigip-ctlr 。 通常,控制器部署在Marathon中。 但是,控制器可以在本地运行以进行开发测试。

    marathon-proxy-manager:marathon mesos 环境的代理和负载平衡设置自动化

    马拉松代理经理用于马拉松 mesos 环境的 Nginx ...安装在终端中安装类型pip install marathon-proxy-manager 执行安装后,您可以使用以下命令启动它: python -m marathon_proxy_manager --marathon-url http://some

    letsencrypt-marathon-lb:让我们为支持DCOS严格安全模式的Marathon-lb进行加密集成

    此应用程序允许您自动生成和更新Marathon-lb的“让我们加密”证书。 它必须作为马拉松应用程序运行。 应用程序在启动时会生成或更新证书,并每隔24小时检查一次是否需要更新证书。 如果您需要新域或其他域的证书,则...

    marathon-python:Mesos Marathon的REST API的Python客户端库

    马拉松蟒 这是一个Python库,用于通过Marathon的与服务器进行。 兼容性 对于Marathon 1.9.x和1.10.x,至少使用0.13.0 对于Marathon 1.6.x,至少使用...pip install -e git+git@github.com:thefactory/marathon-pyth

    marathon-hipache-bridge:应用程序使头痛与马拉松同步

    用法usage: Bridge.groovy [options] -i,--Interval <INTERVAL> Interval in seconds at which the bridge syncs Hipache with Marathon -m,--MarathonUrl <URL> Marathon url -P,--AppsPath <PATH> Example: /v2/...

    Ucode-Half-Marathon-Web

    总的来说,“Ucode-Half-Marathon-Web”项目提供了一个全面学习和提升HTML技能的机会,通过参与,你将能够创建出功能丰富、结构清晰的网页。记得实践中不断尝试和迭代,这是成为优秀Web开发者的关键步骤。

    marathon-demo:Marathon 演示资源

    在提供的压缩包`marathon-demo-master`中,我们可以找到Marathon演示的资源。这个项目可能包含了以下内容: 1. **README.md** - 这是一个Markdown格式的文档,通常会包含演示的介绍、如何运行演示、预期结果以及...

    marathon-docker-search

    marathon-docker-search npm install node app.js <image> search term <ip> search term -h, --help show help -m marathron IP -p docker remote API port (default:4243)

    marathon-shiro-authentication-plugin:用于马拉松的Shiro身份验证插件

    将marathon-shiro-authentication-plugin.jar放在您的插件目录中,并使用--plugin_dir标志提供此目录的路径为Marathon创建配置JSON(例如,在/etc/marathon/plugin_conf.json ){ " plugins " : [ { " plugin " : ...

Global site tag (gtag.js) - Google Analytics