From b0148f1b100794fb97a708a3d5574de54ce8265d Mon Sep 17 00:00:00 2001 From: Andrey Arapov Date: Tue, 19 Sep 2023 12:30:20 +0200 Subject: [PATCH 1/2] feat(bid-script): parametrize price targets via helm chart values --- .../scripts/price_script_generic.sh | 18 +++++----- .../akash-provider/templates/statefulset.yaml | 36 +++++++++++++++++++ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/charts/akash-provider/scripts/price_script_generic.sh b/charts/akash-provider/scripts/price_script_generic.sh index a9baca56..7644910a 100755 --- a/charts/akash-provider/scripts/price_script_generic.sh +++ b/charts/akash-provider/scripts/price_script_generic.sh @@ -121,15 +121,15 @@ gpu_units_requested=$(echo "$data_in" | jq -r '[.[] | (.gpu.units // 0) * .count # Examples: # Hetzner: CPX51 with 16CPU, 32RAM, 360GB disk = $65.81 # Akash: `(1.60*16)+(0.80*32)+(0.04*360)` = $65.60 -TARGET_CPU="1.60" # USD/thread-month -TARGET_MEMORY="0.80" # USD/GB-month -TARGET_HD_EPHEMERAL="0.02" # USD/GB-month -TARGET_HD_PERS_HDD="0.01" # USD/GB-month (beta1) -TARGET_HD_PERS_SSD="0.03" # USD/GB-month (beta2) -TARGET_HD_PERS_NVME="0.04" # USD/GB-month (beta3) -TARGET_ENDPOINT="0.05" # USD for port/month -TARGET_IP="5" # USD for IP/month -TARGET_GPU_UNIT="100" # USD/GPU unit a month +TARGET_CPU="${PRICE_TARGET_CPU:-1.60}" # USD/thread-month +TARGET_MEMORY="${PRICE_TARGET_MEMORY:-0.80}" # USD/GB-month +TARGET_HD_EPHEMERAL="${PRICE_TARGET_HD_EPHEMERAL:-0.02}" # USD/GB-month +TARGET_HD_PERS_HDD="${PRICE_TARGET_HD_PERS_HDD:-0.01}" # USD/GB-month (beta1) +TARGET_HD_PERS_SSD="${PRICE_TARGET_HD_PERS_SSD:-0.03}" # USD/GB-month (beta2) +TARGET_HD_PERS_NVME="${PRICE_TARGET_HD_PERS_NVME:-0.04}" # USD/GB-month (beta3) +TARGET_ENDPOINT="${PRICE_TARGET_ENDPOINT:-0.05}" # USD for port/month +TARGET_IP="${PRICE_TARGET_IP:-5}" # USD for leased IP/month +TARGET_GPU_UNIT="${PRICE_TARGET_GPU_UNIT:-100}" # USD/GPU unit a month ## Example: restrict deployment requests that have services with less 0.1 threads ##echo "$data_in" | jq -r '.[].cpu <= 100' | grep -wq true && { echo -n "$AKASH_OWNER requested deployment with less than 0.1 threads. Aborting!" >&2; exit 1; } diff --git a/charts/akash-provider/templates/statefulset.yaml b/charts/akash-provider/templates/statefulset.yaml index fa04871f..59b39b33 100644 --- a/charts/akash-provider/templates/statefulset.yaml +++ b/charts/akash-provider/templates/statefulset.yaml @@ -187,6 +187,42 @@ spec: {{ if .Values.debug_bid_script }} - name: DEBUG_BID_SCRIPT value: "{{ .Values.debug_bid_script }}" +{{- end }} +{{ if .Values.price_target_cpu }} + - name: PRICE_TARGET_CPU + value: "{{ .Values.price_target_cpu }}" +{{- end }} +{{ if .Values.price_target_memory }} + - name: PRICE_TARGET_MEMORY + value: "{{ .Values.price_target_memory }}" +{{- end }} +{{ if .Values.price_target_hd_ephemeral }} + - name: PRICE_TARGET_HD_EPHEMERAL + value: "{{ .Values.price_target_hd_ephemeral }}" +{{- end }} +{{ if .Values.price_target_hd_pers_hdd }} + - name: PRICE_TARGET_HD_PERS_HDD + value: "{{ .Values.price_target_hd_pers_hdd }}" +{{- end }} +{{ if .Values.price_target_hd_pers_ssd }} + - name: PRICE_TARGET_HD_PERS_SSD + value: "{{ .Values.price_target_hd_pers_ssd }}" +{{- end }} +{{ if .Values.price_target_hd_pers_nvme }} + - name: PRICE_TARGET_HD_PERS_NVME + value: "{{ .Values.price_target_hd_pers_nvme }}" +{{- end }} +{{ if .Values.price_target_endpoint }} + - name: PRICE_TARGET_ENDPOINT + value: "{{ .Values.price_target_endpoint }}" +{{- end }} +{{ if .Values.price_target_ip }} + - name: PRICE_TARGET_IP + value: "{{ .Values.price_target_ip }}" +{{- end }} +{{ if .Values.price_target_gpu_unit }} + - name: PRICE_TARGET_GPU_UNIT + value: "{{ .Values.price_target_gpu_unit }}" {{- end }} - name: AKASH_BID_PRICE_CPU_SCALE value: "{{ .Values.bidpricecpuscale }}" From aceecb0e9277cafa4c43d4aba2c056876d17d0dd Mon Sep 17 00:00:00 2001 From: Andrey Arapov Date: Tue, 19 Sep 2023 13:55:37 +0200 Subject: [PATCH 2/2] feat(bid-script): support setting price per specific GPU model requested --- charts/akash-provider/Chart.yaml | 2 +- .../scripts/price_script_generic.sh | 39 ++++++++++++++++--- .../akash-provider/templates/statefulset.yaml | 6 +-- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/charts/akash-provider/Chart.yaml b/charts/akash-provider/Chart.yaml index dbe52c36..5fdc962f 100644 --- a/charts/akash-provider/Chart.yaml +++ b/charts/akash-provider/Chart.yaml @@ -17,7 +17,7 @@ type: application # Versions are expected to follow Semantic Versioning (https://semver.org/) # Major version bit highlights the mainnet release (e.g. mainnet4 = 4.x.x, mainnet5 = 5.x.x, ...) -version: 6.0.4 +version: 6.0.5 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/charts/akash-provider/scripts/price_script_generic.sh b/charts/akash-provider/scripts/price_script_generic.sh index 7644910a..327f51ca 100755 --- a/charts/akash-provider/scripts/price_script_generic.sh +++ b/charts/akash-provider/scripts/price_script_generic.sh @@ -2,7 +2,7 @@ # WARNING: the runtime of this script should NOT exceed 5 seconds! (Perhaps can be amended via AKASH_BID_PRICE_SCRIPT_PROCESS_TIMEOUT env variable) # Requirements: # curl jq bc mawk ca-certificates -# Version: Sept-08-2023 +# Version: Sept-19-2023 set -o pipefail # Example: @@ -113,8 +113,6 @@ ssd_pers_storage_requested=$(echo "$data_in" | jq -r '[.[] | (.storage[] | selec nvme_pers_storage_requested=$(echo "$data_in" | jq -r '[.[] | (.storage[] | select(.class == "beta3").size // 0) * .count] | add / pow(1024; 3)' | awk '{printf "%.12f\n", $0}') ips_requested=$(echo "$data_in" | jq -r '(map(.ip_lease_quantity//0 * .count) | add)') endpoints_requested=$(echo "$data_in" | jq -r '(map(.endpoint_quantity//0 * .count) | add)') -gpu_units_requested=$(echo "$data_in" | jq -r '[.[] | (.gpu.units // 0) * .count] | add') - # Provider sets the Price he wants to charge in USD/month ## @@ -129,11 +127,42 @@ TARGET_HD_PERS_SSD="${PRICE_TARGET_HD_PERS_SSD:-0.03}" # USD/GB-month (beta2) TARGET_HD_PERS_NVME="${PRICE_TARGET_HD_PERS_NVME:-0.04}" # USD/GB-month (beta3) TARGET_ENDPOINT="${PRICE_TARGET_ENDPOINT:-0.05}" # USD for port/month TARGET_IP="${PRICE_TARGET_IP:-5}" # USD for leased IP/month -TARGET_GPU_UNIT="${PRICE_TARGET_GPU_UNIT:-100}" # USD/GPU unit a month ## Example: restrict deployment requests that have services with less 0.1 threads ##echo "$data_in" | jq -r '.[].cpu <= 100' | grep -wq true && { echo -n "$AKASH_OWNER requested deployment with less than 0.1 threads. Aborting!" >&2; exit 1; } +# GPU pricing per GPU model (USD/GPU unit a month) calculation +## + +# Populate the price target gpu_mappings dynamically based on the "price_target_gpu_mappings" value passed by the helm-chart +# Default: "a100=120,t4=80,*=130" +declare -A gpu_mappings=() + +IFS=',' read -ra PAIRS <<< "${PRICE_TARGET_GPU_MAPPINGS:-a100=120,t4=80,*=130}" +for pair in "${PAIRS[@]}"; do + IFS='=' read -ra KV <<< "$pair" + key="${KV[0]}" + value="${KV[1]}" + gpu_mappings["$key"]=$value +done + +gpu_price_total=0 + +while IFS= read -r resource; do + model=$(echo "$resource" | jq -r '.gpu.attributes.vendor.nvidia.model // 0') + gpu_units=$(echo "$resource" | jq -r '.gpu.units // 0') + # default to 100 USD/GPU per unit a month when PRICE_TARGET_GPU_MAPPINGS is not set + price="${gpu_mappings[''$model'']:-100}" + ((gpu_price_total += gpu_units * price)) + + ## DEBUG + #echo "model $model" + #echo "price for this model $price" + #echo "gpu_units $gpu_units" + #echo "gpu_price_total $gpu_price_total" + #echo "" +done <<< "$(echo "$data_in" | jq -rc '.[]')" + # Calculate the total resource cost for the deployment request in USD ## total_cost_usd_target=$(bc -l <<< "( \ @@ -145,7 +174,7 @@ total_cost_usd_target=$(bc -l <<< "( \ ($nvme_pers_storage_requested * $TARGET_HD_PERS_NVME) + \ ($endpoints_requested * $TARGET_ENDPOINT) + \ ($ips_requested * $TARGET_IP) + \ - ($gpu_units_requested * $TARGET_GPU_UNIT) \ + ($gpu_price_total) \ )") # average block time: 6.117 seconds (based on the time diff between 8090658-8522658 heights [with 432000 blocks as a shift in between if considering block time is 6.0s "(60/6)*60*24*30"]) diff --git a/charts/akash-provider/templates/statefulset.yaml b/charts/akash-provider/templates/statefulset.yaml index 59b39b33..17ff4d9a 100644 --- a/charts/akash-provider/templates/statefulset.yaml +++ b/charts/akash-provider/templates/statefulset.yaml @@ -220,9 +220,9 @@ spec: - name: PRICE_TARGET_IP value: "{{ .Values.price_target_ip }}" {{- end }} -{{ if .Values.price_target_gpu_unit }} - - name: PRICE_TARGET_GPU_UNIT - value: "{{ .Values.price_target_gpu_unit }}" +{{ if .Values.price_target_gpu_mappings }} + - name: PRICE_TARGET_GPU_MAPPINGS + value: "{{ .Values.price_target_gpu_mappings }}" {{- end }} - name: AKASH_BID_PRICE_CPU_SCALE value: "{{ .Values.bidpricecpuscale }}"