Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
132 changes: 116 additions & 16 deletions perfanalysis/perf_analysis_vm_assess.ipynb

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
101 changes: 101 additions & 0 deletions perfanalysis/server_data_creator.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"id": "c35fd21b-7cc2-408f-84fc-f7f99de9c7d2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CSV file 'workers.csv' created with 2000 workers.\n",
"CSV file 'workers_impacts.csv' created with 2000 hardware entries.\n"
]
}
],
"source": [
"import csv\n",
"import random\n",
"\n",
"def generate_workers_csv(n, filename=\"workers.csv\"):\n",
" header = [\n",
" \"id\",\"pool_id\",\"dc_id\",\"power\",\"lifespan\",\"hdd_quantity\",\"hdd_unit_size\",\n",
" \"ssd_quantity\",\"ssd_unit_size\",\"ram_quantity\",\"ram_unit_size\",\"gpu_quantity\",\n",
" \"gpu_model_name\",\"fan_quantity\",\"psu_total_weight\",\"load_rate\",\"comment\",\"quantity\"\n",
" ]\n",
" \n",
" with open(filename, mode=\"w\", newline=\"\") as file:\n",
" writer = csv.writer(file)\n",
" writer.writerow(header)\n",
" \n",
" for i in range(n):\n",
" row = [\n",
" f\"worker-{i}\", # id\n",
" \"worker\", # pool_id\n",
" \"fr01\", # dc_id\n",
" random.uniform(50, 70), # power (random float)\n",
" 1, # lifespan\n",
" \"\", \"\", # hdd_quantity, hdd_unit_size\n",
" \"\", \"\", # ssd_quantity, ssd_unit_size\n",
" random.uniform(30, 64), # ram_quantity (GB)\n",
" \"GB\", # ram_unit_size\n",
" \"\", \"\", # gpu_quantity, gpu_model_name\n",
" \"\", \"\", # fan_quantity, psu_total_weight\n",
" \"\", \"\", # load_rate, comment\n",
" 1 # quantity\n",
" ]\n",
" writer.writerow(row)\n",
" \n",
" print(f\"CSV file '{filename}' created with {n} workers.\")\n",
"\n",
"def generate_workers_impact_csv(n, filename=\"workers_impacts.csv\"):\n",
" header = [\n",
" \"hw_id\",\"lc_step\",\"ADPe\",\"ADPf\",\"AP\",\"CTUe\",\"CTUh_c\",\"CTUh_nc\",\n",
" \"Epf\",\"Epm\",\"Ept\",\"GWP\",\"GWPf\",\"GWPlu\",\"IR\",\"LU\",\"ODP\",\"PM\",\n",
" \"POCP\",\"WU\",\"TPE\",\"GWPb\"\n",
" ]\n",
" \n",
" with open(filename, mode=\"w\", newline=\"\") as file:\n",
" writer = csv.writer(file)\n",
" writer.writerow(header)\n",
" \n",
" for i in range(n):\n",
" row = [\n",
" f\"worker-{i}\", # hw_id\n",
" \"manufacturing\", # lc_step\n",
" *[random.uniform(0, 100) for _ in range(len(header) - 2)]\n",
" ]\n",
" writer.writerow(row)\n",
" \n",
" print(f\"CSV file '{filename}' created with {n} hardware entries.\")\n",
"\n",
"# Example usage\n",
"generate_workers_csv(2000)\n",
"generate_workers_impact_csv(2000)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
2,001 changes: 2,001 additions & 0 deletions perfanalysis/workers.csv

Large diffs are not rendered by default.

2,001 changes: 2,001 additions & 0 deletions perfanalysis/workers_impacts.csv

Large diffs are not rendered by default.

41 changes: 28 additions & 13 deletions src/main/kotlin/org/cloud_assess/service/VirtualMachineService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import ch.kleis.lcaac.core.datasource.in_memory.InMemoryConnectorKeys
import ch.kleis.lcaac.core.datasource.in_memory.InMemoryDatasource
import ch.kleis.lcaac.core.lang.SymbolTable
import ch.kleis.lcaac.core.lang.evaluator.Evaluator
import ch.kleis.lcaac.core.lang.expression.EProcessTemplate
import ch.kleis.lcaac.core.lang.expression.EProcessTemplateApplication
import ch.kleis.lcaac.core.lang.register.DataKey
import ch.kleis.lcaac.core.lang.register.ProcessKey
import ch.kleis.lcaac.core.lang.value.RecordValue
import ch.kleis.lcaac.core.math.basic.BasicNumber
import ch.kleis.lcaac.core.math.basic.BasicOperations
import org.cloud_assess.dto.VirtualMachineListDto
import org.cloud_assess.model.ProductMatcher
import org.cloud_assess.model.ResourceAnalysis
import org.springframework.stereotype.Service
import java.lang.IllegalStateException

@Service
class VirtualMachineService(
Expand All @@ -38,16 +41,17 @@ class VirtualMachineService(
val cases = cases(vms)
val vmsConnector = inMemoryConnector(vms)
val sourceOps = defaultDataSourceOperations.overrideWith(vmsConnector)
val evaluator = Evaluator(
symbolTable.copy(
data = symbolTable.data.override(
DataKey(overrideTimeWindowParam),
period,
)
),
BasicOperations,
sourceOps,

val vmTemplates = cases.entries.map { it.value.template }
val st = symbolTableWith(vmTemplates, symbolTable.copy(
data = symbolTable.data.override(
DataKey(overrideTimeWindowParam),
period,
))
)

val evaluator = Evaluator(st, BasicOperations, sourceOps)

val productMatcher: (String) -> ProductMatcher = { id ->
ProductMatcher(
name = "vm",
Expand All @@ -58,8 +62,7 @@ class VirtualMachineService(
val analysis = cases.entries
.map {
val arguments = it.value.arguments // TODO: override total_vcpu/ram/storage
val trace = evaluator.with(it.value.template)
.trace(it.value.template, arguments)
val trace = evaluator.trace(it.value.template, arguments)
val systemValue = trace.getSystemValue()
val entryPoint = trace.getEntryPoint()
val program = ContributionAnalysisProgram(systemValue, entryPoint)
Expand All @@ -83,9 +86,9 @@ class VirtualMachineService(
val totalStorage = with(helper) { vms.totalStorage.toDataExpression() }
val cases = vms.virtualMachines.associate {
val content = """
process __main__ {
process __${it.id}__ {
products {
1 u __main__
1 u __${it.id}__
}
inputs {
$period vm from vm_fn(
Expand Down Expand Up @@ -128,4 +131,16 @@ class VirtualMachineService(
content = content,
)
}

private fun symbolTableWith(templates: List<EProcessTemplate<BasicNumber>>, st: SymbolTable<BasicNumber>): SymbolTable<BasicNumber> {
val processTemplates = templates.map {
val processKey = ProcessKey(it.body.name)
if (st.processTemplates[processKey] != null) throw IllegalStateException("Process ${it.body.name} already exists")
processKey to it
}

return st.copy(
processTemplates = this.symbolTable.processTemplates.plus(processTemplates)
)
}
}
Loading