XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Tag-Based Automation: Manage VM CPU Priority via assigned tag.

    Scheduled Pinned Locked Moved Management
    1 Posts 1 Posters 12 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      johnnezero
      last edited by johnnezero

      WHAT: Automatically assigns CPU weights and I/O priorities based on assigned VM tag (i.e. replicating what vcenter did via resource pools etc.).

      HOW: Run via cron for regular enforcement.

      WHY: Automatically assign performance metrics on all pool VMs (as well as preventing configuration drift if settings are accidentally changed).

      TAGS: The Performance Tiering Concept: 4-tier system with a naming convention that sorts logically in XO:

      TAG       CPU WEIGHT  I/O PRIORITY      USE CASE
      0-core    2048        7 (Highest)       Domain Controllers, DNS, DHCP, Core DBs
      1-high    1024        7                 Critical App Servers
      2-normal   256        4                 Standard Workloads
      3-low      128        1                 Dev/Test, Noisy Neighbors
      

      Why the "0-" prefix? It forces core VMs to the top of the VM list in XO for easy visibility and management.

      Important: CPU weights only matter during contention. When the host is under-utilized, all VMs get the performance they need regardless of weight. These are an insurance policy.

      Script: set-performace.sh

      bash
      #!/bin/bash
      
      # ============================================
      # XCP-ng set-performace.sh script
      # Tags: 0-core, 1-high, 2-normal, 3-low
      # ============================================
      
      # --- CONFIGURATION (Customize these for your environment) ---
      CORE_TAG="0-core"
      CORE_WEIGHT="2048"
      CORE_IO_PRI="7"
      
      HIGH_TAG="1-high"
      HIGH_WEIGHT="1024"
      HIGH_IO_PRI="7"
      
      NORMAL_TAG="2-normal"
      NORMAL_WEIGHT="256"
      NORMAL_IO_PRI="4"
      
      LOW_TAG="3-low"
      LOW_WEIGHT="128"
      LOW_IO_PRI="1"
      LOW_QOS_KBPS="100000"  # 100Mbps cap for noisy neighbors
      
      # --- CORE CRITICAL VMs ---
      echo "=== Applying $CORE_TAG CPU & I/O Priority ==="
      xe vm-list tags:contains="$CORE_TAG" --minimal | tr ',' '\n' | while read uuid; do
          [ -z "$uuid" ] && continue
          xe vm-param-set uuid=$uuid VCPUs-params:weight=$CORE_WEIGHT
          xe vm-param-set uuid=$uuid other-config:sched-pri=$CORE_IO_PRI
          echo "CORE CRITICAL priority applied: $uuid"
      done
      
      # --- HIGH PRIORITY VMs ---
      echo "=== Applying $HIGH_TAG CPU & I/O Priority ==="
      xe vm-list tags:contains="$HIGH_TAG" --minimal | tr ',' '\n' | while read uuid; do
          [ -z "$uuid" ] && continue
          xe vm-param-set uuid=$uuid VCPUs-params:weight=$HIGH_WEIGHT
          xe vm-param-set uuid=$uuid other-config:sched-pri=$HIGH_IO_PRI
          echo "HIGH priority applied: $uuid"
      done
      
      # --- NORMAL PRIORITY VMs ---
      echo "=== Applying $NORMAL_TAG CPU & I/O Priority ==="
      xe vm-list tags:contains="$NORMAL_TAG" --minimal | tr ',' '\n' | while read uuid; do
          [ -z "$uuid" ] && continue
          xe vm-param-set uuid=$uuid VCPUs-params:weight=$NORMAL_WEIGHT
          xe vm-param-set uuid=$uuid other-config:sched-pri=$NORMAL_IO_PRI
          echo "NORMAL priority applied: $uuid"
      done
      
      # --- LOW PRIORITY VMs (with Network QoS cap) ---
      echo "=== Applying $LOW_TAG CPU & I/O Priority ==="
      xe vm-list tags:contains="$LOW_TAG" --minimal | tr ',' '\n' | while read uuid; do
          [ -z "$uuid" ] && continue
          xe vm-param-set uuid=$uuid VCPUs-params:weight=$LOW_WEIGHT
          xe vm-param-set uuid=$uuid other-config:sched-pri=$LOW_IO_PRI
          echo "LOW priority applied: $uuid"
      done
      
      echo "=== Performance Tuning Complete! ==="
      

      How to Deploy:

      1 Upload script

      bash
      # Copy to your pool master
      scp set-performace.sh root@your-pool-master:/usr/local/bin/
      chmod +x /usr/local/bin/set-performace.sh
      

      2 Add to crontab

      # Add to crontab (runs hourly)
      */60 * * * * root /usr/local/bin/set-performance.sh >> /var/log/set-performance.log 2>&1
      

      3 Test

      # Test it manually
      /usr/local/bin/set-performace.sh
      
      1 Reply Last reply Reply Quote 0

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      • First post
        Last post