Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Using Heroku to build Heroku Postgres

Using Heroku to build Heroku Postgres

Introduces how Heroku works and how the primitives around processes, dynos and apps are used to build a complex system consisting of a constellation of applications collaborating with each other to run the Heroku Postgres platform.

Presented on November 21st 2013 at Dreamforce in SF.

Harold Giménez

November 22, 2013
Tweet

More Decks by Harold Giménez

Other Decks in Technology

Transcript

  1. Creating demo-app... done, region is us http://demo-app.herokuapp.com/ | [email protected]:demo- app.git

    Git remote heroku added $ $ heroku apps:create demo-app ----> Heroku receiving push ----> Rails app detected ----> Compiled slug size is 8.0MB http://demo-app.herokuapp.com deployed to Heroku $ git push heroku master
  2. web: bundle exec thin start -p $PORT -e $RACK_ENV worker:

    bundle exec rake worker --trace clock: bundle exec bin/clock $ $ cat Procfile foreman start 18:08:22 web.1 | started with pid 3371 18:08:22 worker.1 | started with pid 3372 18:08:22 clock.1 | started with pid 3373
  3. Scaling web dynos... done, now running 10 Scaling worker dynos...

    done, now running 5 $ $ heroku ps:scale web=10 worker=5 -a demo-app
  4. Adding loggly on demo-app… done, v161 (free) Use `heroku addons:docs

    loggly` to view documentation. $ $ heroku addons:add loggly
  5. Adding heroku-postgresql on demo-app… done, v129 (free) Attached as HEROKU_POSTGRESQL_ORANGE_URL

    Database has been created and is available Use `heroku addons:docs heroku-postgresql` to view documentation. $ $ heroku addons:add heroku-postgresql --app demo-app Plan: Dev Status: available Connections: 1 PG Version: 9.2.4 Data Size: 6.3 MB Tables: 0 Rows: 0/10000 (In compliance) Fork/Follow: Unsupported heroku pg:info -a demo-app
  6. Heroku Postgres v0 A sinatra app implementing the heroku addons

    API create servers install postgres service create database for user - a “Resource” Sequel talks to postgres stem talks to AWS
  7. class Resource def feel observations.create( Feeler.new(self).current_environment ) end end !

    class Feeler def current_environment { services_available?: service_available?, connections: connections, row_count: row_count, table_count: table_count, seq_scans: seq_scans, index_scans: index_scans } end end
  8. class Resource include Stateful ! state :available do unless service_available?

    transition :uncertain end end end ! resource = Resource.find resource.transition :available resource.feel resource.tick puts resource.state # => :uncertain
  9. module Stateful def self.included(base) base.extend ClassMethods end ! module ClassMethods

    def state(name, &block) state[name] = block end def states; @states ||={}; end end ! def tick self.instance_eval( &self.class.states[self.state.to_sym] ) end def transition(state); end end
  10. db1 db2 db3 db4 db5 db6 db7 db8 dbn W

    orkers db1.feel
 db1.tick
  11. INSERT INTO … 1. Write to WAL 2. Keep it

    in memory 4. Flush to disk 3. Respond to client
  12. Rails Sinatra sequel fog ruby python bash go coffeescript backbone.js

    Dashboard Dataclips Resources Heroku Admin UI Participants
 Timelines
 Servers CLI infra Monitoring