
dejan at suse
Aug 19, 2011, 5:18 AM
Views: 2539
Permalink
|
Hi John, On Thu, Aug 18, 2011 at 12:20:26AM -0600, John Shi wrote: > > > > >>> "John Shi" <jshi [at] novell> 8/13/2011 2:56 上午 >>> > > > >>> Lars Marowsky-Bree <lmb [at] suse> 07/22/11 7:40 ?? >>> > On 2011-07-13T22:56:06, John Shi <jshi [at] novell> wrote: > > >> how can we know that node is ready to run Xen RA or other RA, Xen RA > >> cares about the memory which is "physical_mem - (dom0_min_mem + > >> domU_mem * run_num)" but other RA just care about the physical memory > >> or dom0 memory(Xen kernel). > >> > >> Can we separate the memory of utilization to dom0_mem and domU_mem ? > > > >Indeed, there's a difference between the memory available to the > >hypervisor/domain 0/base OS and that available for running guests; this > >probably should be handled by os_mem and vm_mem. > > > >I think the main use case with virtualized environments is that they run > >"just" VMs, so nobody cares about the memory available in the HVM, but > >you're right, it's good to have a clean separation immediately. > > > >Good catch! > > > Hi, > Xinwei Hu and I improved the 2 resource-agents patches, > 1. Separate the memory of utilization to host_memory and hypervisor_memory. > 2. Add some parameters for cpu/memory reservation. > 3. VirtualDomain RA just cares about hypervisor_memory. > > I know more details we need to discuss, but could we put them into upstream first ? I wasn't involved in the discussion earlier. Can you please reiterate which details are still open? Also, should the new NodeUtilization RA go into the pacemaker tree? Cheers, Dejan P.S. Is this a resend of the same patches you sent on Aug 12? > We can gradually improve these features in future. > > Regards, > John > From 9071409ecd0e0951af74a7823d5d2f712a0f22f3 Mon Sep 17 00:00:00 2001 > From: John Shi <jshi [at] novell> > Date: Sat, 13 Aug 2011 02:18:50 +0800 > Subject: [PATCH] Build: Add a new agent: NodeUtilization. > This agent detects system parameters and put them into CIB by crm_attribute, > and it runs on every node as clone resource. > > --- > heartbeat/Makefile.am | 1 + > heartbeat/NodeUtilization | 229 +++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 230 insertions(+), 0 deletions(-) > create mode 100755 heartbeat/NodeUtilization > > diff --git a/heartbeat/Makefile.am b/heartbeat/Makefile.am > index dacf3bd..3a3d221 100644 > --- a/heartbeat/Makefile.am > +++ b/heartbeat/Makefile.am > @@ -77,6 +77,7 @@ ocf_SCRIPTS = ClusterMon \ > mysql \ > mysql-proxy \ > nfsserver \ > + NodeUtilization \ > oracle \ > oralsnr \ > pingd \ > diff --git a/heartbeat/NodeUtilization b/heartbeat/NodeUtilization > new file mode 100755 > index 0000000..dca0d9a > --- /dev/null > +++ b/heartbeat/NodeUtilization > @@ -0,0 +1,229 @@ > +#!/bin/sh > +# > +# > +# NodeUtilization OCF Resource Agent > +# > +# Copyright (c) 2011 SUSE LINUX, John Shi > +# All Rights Reserved. > +# > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of version 2 of the GNU General Public License as > +# published by the Free Software Foundation. > +# > +# This program is distributed in the hope that it would be useful, but > +# WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > +# > +# Further, this software is distributed without any warranty that it is > +# free of the rightful claim of any third person regarding infringement > +# or the like. Any license provided herein, whether implied or > +# otherwise, applies only to this software file. Patent licenses, if > +# any, provided herein do not apply to combinations of this program with > +# other software, or any other product whatsoever. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program; if not, write the Free Software Foundation, > +# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. > +# > +####################################################################### > +# Initialization: > + > +: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} > +. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs > + > +####################################################################### > + > +meta_data() { > + cat <<END > +<?xml version="1.0"?> > +<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd"> > +<resource-agent name="NodeUtilization"> > +<version>1.0</version> > + > +<longdesc lang="en"> > +This is an NodeUtilization Resource Agent. > +This agent detects system parameters and put them into CIB by crm_attribute, > +and it runs on every node as clone resource. > +</longdesc> > +<shortdesc lang="en">NodeUtilization resource agent</shortdesc> > + > +<parameters> > +<parameter name="dynamic" unique="0" required="0"> > +<longdesc lang="en"> > +If set, some of the HA parameters will be reset if there are > +difference between HA parameters and system parameters when HA monitor. > +Otherwise, the HA parameters will be set once when the resource instance starts. > +</longdesc> > +<shortdesc lang="en">Set HA parameters when start or monitor</shortdesc> > +<content type="boolean" default="true" /> > +</parameter> > + > +<parameter name="utilization_cpu" unique="0" required="0"> > +<longdesc lang="en">Enable setting cpu utilization.</longdesc> > +<shortdesc lang="en">Enable setting cpu utilization.</shortdesc> > +<content type="boolean" default="true" /> > +</parameter> > + > +<parameter name="utilization_cpu_reservation" unique="0" required="0"> > +<longdesc lang="en">CPU reserved for non-HA related usage.</longdesc> > +<shortdesc lang="en">CPU reserved for non-HA related usage.</shortdesc> > +<content type="integer" default="1" /> > +</parameter> > + > +<parameter name="utilization_host_memory" unique="0" required="0"> > +<longdesc lang="en">Enable setting memory utilization of host.</longdesc> > +<shortdesc lang="en">Enable setting memory utilization of host.</shortdesc> > +<content type="boolean" default="true" /> > +</parameter> > + > +<parameter name="utilization_host_memory_reservation" unique="0" required="0"> > +<longdesc lang="en">Memory reserved for other services inside host, in MB.</longdesc> > +<shortdesc lang="en">Memory reserved for other services inside host, in MB.</shortdesc> > +<content type="integer" default="512" /> > +</parameter> > + > +<parameter name="utilization_hv_memory" unique="0" required="0"> > +<longdesc lang="en">Enable setting the memory utilization of hypervisor.</longdesc> > +<shortdesc lang="en">Enable setting the memory utilization of hypervisor.</shortdesc> > +<content type="boolean" default="true" /> > +</parameter> > + > +<parameter name="utilization_hv_memory_reservation" unique="0" required="0"> > +<longdesc lang="en">Memory reserved for the hypervisor, in MB.</longdesc> > +<shortdesc lang="en">Memory reserved for the hypervisor, in MB.</shortdesc> > +<content type="integer" default="512" /> > +</parameter> > +</parameters> > + > +<actions> > +<action name="start" timeout="90" /> > +<action name="stop" timeout="100" /> > +<action name="monitor" timeout="20s" interval="60s"/> > +<action name="meta-data" timeout="5" /> > +<action name="validate-all" timeout="30" /> > +</actions> > +</resource-agent> > +END > +} > + > +set_utilization() { > + host_name="$(hostname)" > + > + if [ "$OCF_RESKEY_utilization_cpu" = "true" -o "$OCF_RESKEY_utilization_cpu" = "1" ]; then > + sys_cpu=$(( $(grep -c processor /proc/cpuinfo) - $OCF_RESKEY_utilization_cpu_reservation )) > + uti_cpu=$(crm_attribute -Q -t nodes -U "$host_name" -z -n cpu 2>/dev/null) > + > + if [ "$sys_cpu" != "$uti_cpu" ]; then > + if ! crm_attribute -t nodes -U "$host_name" -z -n cpu -v $sys_cpu; then > + ocf_log err "Failed to set cpu of utilization by crm_attribute." > + return 1 > + fi > + fi > + fi > + > + if [ "$OCF_RESKEY_utilization_host_memory" = "true" -o "$OCF_RESKEY_utilization_host_memory" = "1" ]; then > + sys_mem=$(( $(awk '/MemTotal/{printf("%d\n",$2/1024);exit(0)}' /proc/meminfo) - $OCF_RESKEY_utilization_host_memory_reservation )) > + uti_mem=$(crm_attribute -Q -t nodes -U "$host_name" -z -n host_memory 2>/dev/null) > + > + if [ "$sys_mem" != "$uti_mem" ]; then > + if ! crm_attribute -t nodes -U "$host_name" -z -n host_memory -v $sys_mem; then > + ocf_log err "Failed to set host_memory of utilization by crm_attribute." > + return 1 > + fi > + fi > + fi > + > + if [ -x /usr/sbin/xm ]; then > + if [ "$OCF_RESKEY_utilization_hv_memory" = "true" -o "$OCF_RESKEY_utilization_hv_memory" = "1" ]; then > + hv_mem=$(( $(xm info | awk '/max_free_memory/{printf("%d\n",$3);exit(0)}') - $OCF_RESKEY_utilization_hv_memory_reservation )) > + uti_mem=$(crm_attribute -Q -t nodes -U "$host_name" -z -n hv_memory 2>/dev/null) > + > + if [ "$hv_mem" != "$uti_mem" ]; then > + if ! crm_attribute -t nodes -U "$host_name" -z -n hv_memory -v $hv_mem; then > + ocf_log err "Failed to set hv_memory of utilization by crm_attribute." > + return 1 > + fi > + fi > + fi > + fi > +} > + > +NodeUtilization_usage() { > + cat <<END > +usage: $0 {start|stop|monitor|validate-all|meta-data} > + > +Expects to have a fully populated OCF RA-compliant environment set. > +END > +} > + > +NodeUtilization_start() { > + if ! touch "$OCF_RESKEY_pidfile"; then > + ocf_log err "Failed to touch pidfile: ${OCF_RESKEY_pidfile}." > + exit $OCF_ERR_GENERIC > + fi > + if [ "$OCF_RESKEY_dynamic" = "false" -o "$OCF_RESKEY_dynamic" = "0" ]; then > + if ! set_utilization; then > + exit $OCF_ERR_GENERIC > + fi > + fi > + exit $OCF_SUCCESS > +} > + > +NodeUtilization_stop() { > + rm -f $OCF_RESKEY_pidfile > + exit $OCF_SUCCESS > +} > + > +NodeUtilization_monitor() { > + if [ ! -f $OCF_RESKEY_pidfile ]; then > + exit $OCF_NOT_RUNNING > + fi > + > + if [ "$OCF_RESKEY_dynamic" = "true" -o "$OCF_RESKEY_dynamic" = "1" ]; then > + if ! set_utilization; then > + exit $OCF_ERR_GENERIC > + fi > + fi > + exit $OCF_SUCCESS > +} > + > +NodeUtilization_validate() { > + exit $OCF_SUCCESS > +} > + > + > +: ${OCF_RESKEY_pidfile:="$HA_VARRUN/NodeUtilization-${OCF_RESOURCE_INSTANCE}"} > +: ${OCF_RESKEY_dynamic:="true"} > +: ${OCF_RESKEY_utilization_cpu:="true"} > +: ${OCF_RESKEY_utilization_cpu_reservation="1"} > +: ${OCF_RESKEY_utilization_hv_memory:="true"} > +: ${OCF_RESKEY_utilization_hv_memory_reservation="512"} > +: ${OCF_RESKEY_utilization_host_memory:="true"} > +: ${OCF_RESKEY_utilization_host_memory_reservation="512"} > + > +if [ $# -ne 1 ]; then > + NodeUtilization_usage > + exit $OCF_ERR_ARGS > +fi > + > +case $__OCF_ACTION in > +meta-data) meta_data > + exit $OCF_SUCCESS > + ;; > +start) NodeUtilization_start > + ;; > +stop) NodeUtilization_stop > + ;; > +monitor) NodeUtilization_monitor > + ;; > +validate-all) NodeUtilization_validate > + ;; > +usage|help) NodeUtilization_usage > + exit $OCF_SUCCESS > + ;; > +*) NodeUtilization_usage > + exit $OCF_ERR_UNIMPLEMENTED > + ;; > +esac > + > +exit $? > -- > 1.7.2.5 > > From 3f26aa2cf5f9f7da40182008079c6ea7498f96fd Mon Sep 17 00:00:00 2001 > From: John Shi <jshi [at] novell> > Date: Sat, 13 Aug 2011 02:25:37 +0800 > Subject: [PATCH] Low: VirtualDomain: Add a functionality that modifiesutilization of resource automatically. > > --- > heartbeat/VirtualDomain | 67 +++++++++++++++++++++++++++++++++++++++++++++++ > 1 files changed, 67 insertions(+), 0 deletions(-) > > diff --git a/heartbeat/VirtualDomain b/heartbeat/VirtualDomain > index 0786944..d9321d9 100755 > --- a/heartbeat/VirtualDomain > +++ b/heartbeat/VirtualDomain > @@ -19,9 +19,15 @@ > # Defaults > OCF_RESKEY_force_stop_default=0 > OCF_RESKEY_hypervisor_default="$(virsh --quiet uri)" > +OCF_RESKEY_dynamic_utilization_default="true" > +OCF_RESKEY_set_utilization_cpu_default="true" > +OCF_RESKEY_set_utilization_memory_default="true" > > : ${OCF_RESKEY_force_stop=${OCF_RESKEY_force_stop_default}} > : ${OCF_RESKEY_hypervisor=${OCF_RESKEY_hypervisor_default}} > +: ${OCF_RESKEY_dynamic_utilization=${OCF_RESKEY_dynamic_utilization_default}} > +: ${OCF_RESKEY_set_utilization_cpu=${OCF_RESKEY_set_utilization_cpu_default}} > +: ${OCF_RESKEY_set_utilization_memory=${OCF_RESKEY_set_utilization_memory_default}} > ####################################################################### > > ## I'd very much suggest to make this RA use bash, > @@ -117,6 +123,28 @@ Be sure to set the timeout of these operations to accommodate this delay. > <content type="string" default="" /> > </parameter> > > +<parameter name="dynamic_utilization" unique="0" required="0"> > +<longdesc lang="en"> > +If set, the utilization parameter of resource will be reset if there are > +difference between resource parameters and system parameters when agent monitor. > +Otherwise, the resource parameters will be set once when agent start. > +</longdesc> > +<shortdesc lang="en">Set utilization of resource when agent monitor</shortdesc> > +<content type="boolean" default="true" /> > +</parameter> > + > +<parameter name="set_utilization_cpu" unique="0" required="0"> > +<longdesc lang="en">Enable setting cpu of utilization.</longdesc> > +<shortdesc lang="en">Enable setting cpu of utilization</shortdesc> > +<content type="boolean" default="true" /> > +</parameter> > + > +<parameter name="set_utilization_memory" unique="0" required="0"> > +<longdesc lang="en">Enable setting memory of utilization.</longdesc> > +<shortdesc lang="en">Enable setting memory of utilization</shortdesc> > +<content type="boolean" default="true" /> > +</parameter> > + > </parameters> > > <actions> > @@ -133,6 +161,33 @@ Be sure to set the timeout of these operations to accommodate this delay. > EOF > } > > +set_utilization() { > + local dom_cpu dom_mem > + local uti_cpu uti_mem > + > + read dom_cpu dom_mem <<EOF > +$(LANG=C virsh $VIRSH_OPTIONS dominfo ${DOMAIN_NAME} | > +awk '/CPU\(s\)/{cpu=$2} /Max memory/{mem=$3} END{printf("%d %d\n", cpu, mem/1024)}') > +EOF > + uti_cpu=$(crm_resource -Q -r $OCF_RESOURCE_INSTANCE -z -g cpu 2>/dev/null) > + uti_mem=$(crm_resource -Q -r $OCF_RESOURCE_INSTANCE -z -g hv_memory 2>/dev/null) > + > + if [ "$OCF_RESKEY_set_utilization_cpu" = "true" -o "$OCF_RESKEY_set_utilization_cpu" = "1" ]; then > + if [ "$dom_cpu" != "$uti_cpu" ]; then > + if ! crm_resource -r $OCF_RESOURCE_INSTANCE -z -p cpu -v $dom_cpu; then > + ocf_log warn "Failed to set cpu of utilization by crm_resource." > + fi > + fi > + fi > + if [ "$OCF_RESKEY_set_utilization_memory" = "true" -o "$OCF_RESKEY_set_utilization_memory" = "1" ]; then > + if [ "$dom_mem" != "$uti_mem" ]; then > + if ! crm_resource -r $OCF_RESOURCE_INSTANCE -z -p hv_memory -v $dom_mem; then > + ocf_log warn "Failed to set hv_memory of utilization by crm_resource." > + fi > + fi > + fi > +} > + > # Set options to be passed to virsh: > VIRSH_OPTIONS="--connect=${OCF_RESKEY_hypervisor} --quiet" > > @@ -236,6 +291,11 @@ VirtualDomain_Start() { > while ! VirtualDomain_Monitor; do > sleep 1 > done > + > + if [ "$OCF_RESKEY_dynamic_utilization" = "false" -o "$OCF_RESKEY_dynamic_utilization" = "0" ]; then > + set_utilization > + fi > + > return $OCF_SUCCESS > } > > @@ -404,6 +464,13 @@ VirtualDomain_Monitor() { > fi > done > fi > + > + if [ "$OCF_RESKEY_dynamic_utilization" = "true" -o "$OCF_RESKEY_dynamic_utilization" = "1" ]; then > + if ocf_is_probe; then > + set_utilization > + fi > + fi > + > return ${rc} > } > > -- > 1.7.2.5 > _______________________________________________ ha-wg-technical mailing list ha-wg-technical [at] lists https://lists.linux-foundation.org/mailman/listinfo/ha-wg-technical
|