Project checkpoint: AWS spot market simulator

Finally settled on a structure that seems to work. My initial design was doing everything in Ruby by shuffling elements between sets and hashes and this was a little hard to follow. After stepping back from the problem I noticed that I was basically re-inventing database tables very poorly so I shifted everything to using an in-memory SQLite database.

Update: I’ve now written a simulator that can be used for testing bidding and control strategies without having to pay for actual server time.

It’s not as fast as the pure Ruby version but speed isn’t really the main concern. I only need something to be able to validate my control strategies and currently the code is plenty fast for doing that. The schema for the state looks as follows

database diagram for aws spot simulator

SQLite schema

The main tables that evolve through the duration of the simulation are requests, request_history, and timers. The other tables are populated during initialization and then used for various table joins and in cases where there is no joining to be done then the table is loaded into memory as a hash map for fast access and update.

The logic of the simulation looks as follows

Simulation loop logic

Sequence of simulation actions

I’ll do a more thorough write-up of what the main simulation loop is actually doing once everything is in a more polished state.