SlideShare une entreprise Scribd logo
1  sur  19
Heroku waza 2013
      Lessons Learned
                                Simon Bagreev
                        Twitter: @status_200
                               Github: semmin
I attended
Keynote - Michael Lopp
• Why Python, Ruby and Javascript are Slow - Alex Gaynor
• Heroku Secrets - Noah Zoske
• API VS Game: Fight! - Wesley Beary
• Predictable Failure - Ryan Smith
• Postgres: The bits you haven’t found - Peter Van Hardenberg
• Mobile is Not Different - Matt Thompson
• Everything is a Remix - Kirby Ferguson
liked the most
• Keynote - Michael Lopp
• Why Python, Ruby and Javascript are Slow - Alex Gaynor
• Heroku Secrets - Noah Zoske
• API VS Game: Fight! - Wesley Beary
• Predictable Failure - Ryan Smith
• Postgres: The bits you haven’t found - Peter Van Hardenberg
• Mobile is Not Different - Matt Thompson
• Everything is a Remix - Kirby Ferguson
postgres: 12 bits you
   haven’t found
       Made me realize
postgres: 12 bits you
              haven’t found
• psql -- postgres console -- very powerful
• need to upgrade to 9.2
• tons of tools, extensions, types
• tools for monitoring, BI
WITH operator
                      Auxiliary statements for use in larger queries

WITH status_with_next AS (
   SELECT *, lead(state, 1) OVER (partition by agent_uuid order by time) as next from
agent_statuses
),
oops AS (
   SELECT * from status_with_next WHERE state = 'training' and next = 'captured'
)
SELECT name, count(*) as training_captures from oops join agents on agents.uuid =
agent_uuid GROUP BY name ORDER by training_captures DESC;
ARRAys
-- create
CREATE TABLE jobseekers (
    email           text,
    industries      integer[],
    ...
);

-- insert
INSERT INTO jobseekers(email, zip, industries, source, created_at, updated_at) VALUES ('
sbagreev@gmail.com', '23453', '{1,2,3}', 'EG', now(), now());
INSERT INTO jobseekers(email, zip, industries, source, created_at, updated_at) VALUES
('simon.bagreev@gmail.com', '23453', '{4,5,6}', 'EG', now(), now());

-- query by inclusion @>
SELECT email FROM jobseekers WHERE industries @> ARRAY[3,1];
-- > sbagreev@gmail.com

-- query by intersection &&
SELECT email FROM jobseekers WHERE industries && ARRAY[4];
-- > simon.bagreev@gmail.com
dblink
                      Connect to other Postgres Databases
-- add extension
CREATE EXTENSION dblink;

-- connect to the external database
SELECT dblink_connect('quasar_connection','dbname=quasar_development');
 dblink_connect
----------------
 OK
(1 row)

-- query remote database
SELECT * FROM dblink('quasar_connection', 'select id, email from users') AS
quasar_users(id int, email varchar(255));

 id |                 email
----+----------------------------------------
 24 | user1@gmail.com
 23 | sbagreev@gmail.com
 29 | simon.bagreev@gmail.com
 25 | user5@employmentguide.com
listen / notify
            Postgres’ own queueing, used to send notifications to clients
-- create listener
LISTEN USER_UPDATES;

/* send notification to listeners
   can be done from trigger */
NOTIFY USER_UPDATES, 'User with id=23 just changed email';

-- on the listener
Asynchronous notification "user_updates" with payload "User with id=23 just changed
email" received from server process with PID 81016.
regexes
-- pattern matching
SELECT 'foo bar baz' ~ 's+baz' as matches_pattern;

-- search and replace
UPDATE jobseekers SET zip = regexp_replace(zip, '23', '45');

SELECT zip FROM jobseekers;
  zip
-------
 45451
 45451
-- add extension
                                UUIDs
CREATE EXTENSION "uuid-ossp";

-- create table with uuid as PK
CREATE TABLE t (uuid uuid PRIMARY KEY DEFAULT uuid_generate_v4(), name text);

d t
                  Table "public.t"
 Column | Type |              Modifiers
--------+------+-------------------------------------
 uuid   | uuid | not null default uuid_generate_v4()
 name   | text |

INSERT INTO t(name) VALUES ('foo');

SELECT * FROM t;
                 uuid                 | name
--------------------------------------+------
 7f7941f3-6705-4c28-8028-d1ee5e8d3b8b | foo
-- add extension
                                           hstore !!!
CREATE EXTENSION hstore;
-- create applications table with custom attributes
CREATE TABLE job_applications(uuid uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
                              attrs hstore,
                              company_id integer);

-- company 1 wants only name and email in their applications
INSERT INTO job_applications (company_id, attrs) VALUES (1, 'name => "Simon Bagreev", email => "
sbagreev@gmail.com"');

-- company 2 also wants address
INSERT INTO job_applications (company_id, attrs) VALUES (2, 'name => "Simon Bagreev", email =>
"sbagreev@gmail.com", address => "123 Broadwalk St"');

-- company 3 wants phone number too
INSERT INTO job_applications (company_id, attrs) VALUES (3, 'name => "Simon Bagreev", email =>
"sbagreev@gmail.com", address => "123 Broadwalk St", phone => "7570000000"');

SELECT * from job_applications;
                                                    attrs                                                    | company_id
-------------------------------------------------------------------------------------------------------------+------------
 "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com"                                                      |          1
 "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com", "address"=>"123 Broadwalk St"                       |          2
 "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com", "phone"=>"7570000000", "address"=>"123 Broadwalk St"|          3
hstore
                                              Can add / delete keys


-- company 1 decides to add a phone number to the app
UPDATE job_applications SET attrs = attrs || 'phone=>7573518500'::hstore WHERE company_id=1;

SELECT attrs, company_id FROM job_applications;
                                                    attrs                                                    | company_id
-------------------------------------------------------------------------------------------------------------+------------
 "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com", "address"=>"123 Broadwalk St"                       |          2
 "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com", "phone"=>"7570000000", "address"=>"123 Broadwalk St"|          3
 "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com", "phone"=>"7570000000"                               |          1
hstore
                                                      Querying

-- what companies are using address on their application?
SELECT attrs, company_id FROM job_applications WHERE attrs ? 'address';
                                                    attrs                                                     | company_id
-------------------------------------------------------------------------------------------------------------+------------
 "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com", "address"=>"123 Broadwalk St"                        |          2
 "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com", "phone"=>"7573518500", "address"=>"123 Broadwalk St" |          3

-- find all applicants with address 123 Broadwalk
SELECT attrs, company_id FROM job_applications WHERE attrs @> 'address=>"123 Broadwalk St"'::hstore;
                                                    attrs                                                     | company_id
-------------------------------------------------------------------------------------------------------------+------------
 "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com", "address"=>"123 Broadwalk St"                        |          2
 "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com", "phone"=>"7573518500", "address"=>"123 Broadwalk St" |          3
HSTore
• can be indexed
• searchable
postgres has more to offer
•   full-text search
•   TOAST - store large values
•   pgcrypto - encryption for your DB
•   pg_stat_activity, pg_stat_statements - stats
•   postGIS - geographical awesomeness
•   JSON and PL/V8 -- schemaless SQL
heroku secrets presentation
•   use --version=9.2 flag when adding Postgres addon on Heroku
•   encrypt your app’s config, store it on AWS
•   use multi-processed and multi-threaded servers
•   dataclips! - read-only, easy-to-share quick database queries, exportable to
    many formats, can export data to Google docs
Before / After
                                Questions I had going there:
• Q: Want to hear more explanations about recent “dumb routing issue”, and suggestions from
    Heroku to make it “smarter”, especially on Cedar stack.
•   A: Doesn’t affect Cedar multi-threaded environment
•   Q: Want to learn more about multi-threading and multi-processing on Heroku (does it make
    sense to do it in Rails/Heroku? If so, how?).
•   A: Unicorn for multi-process, JRuby + JVM for multi-threading
•   Q: When is Rails 4.0 / Ruby 2.0 will be officially supported by Heroku?
•   A: Already is.
•   Q: Will Heroku support multiple availability zones (US-West, Asia)?
•   A: In Beta (US West, EU)
Before / After
                               Questions I had going there:
• Q: Will the SLA (99.99% uptime) be improved any time soon?
• A: Constantly working on it
• Q: Want learn more tricks for increasing performance on Heroku, and running large enterprise-
    scale applications.
•   A: Many-many options

Contenu connexe

Tendances

Seistech SQL code
Seistech SQL codeSeistech SQL code
Seistech SQL codeSimon Hoyle
 
Dipôles linéaires, régime transitoire
Dipôles linéaires, régime transitoireDipôles linéaires, régime transitoire
Dipôles linéaires, régime transitoireAchraf Ourti
 
Ruby Language: Array, Hash and Iterators
Ruby Language: Array, Hash and IteratorsRuby Language: Array, Hash and Iterators
Ruby Language: Array, Hash and IteratorsSarah Allen
 
MongoDB.local Seattle 2019: Tips & Tricks for Avoiding Common Query Pitfalls
MongoDB.local Seattle 2019: Tips & Tricks for Avoiding Common Query PitfallsMongoDB.local Seattle 2019: Tips & Tricks for Avoiding Common Query Pitfalls
MongoDB.local Seattle 2019: Tips & Tricks for Avoiding Common Query PitfallsMongoDB
 
Global Change, Species Diversity, and the Future of Marine Ecosystems
Global Change, Species Diversity, and the Future of Marine EcosystemsGlobal Change, Species Diversity, and the Future of Marine Ecosystems
Global Change, Species Diversity, and the Future of Marine EcosystemsJarrett Byrnes
 
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"PromptWorks
 
MySQL's JSON Data Type and Document Store
MySQL's JSON Data Type and Document StoreMySQL's JSON Data Type and Document Store
MySQL's JSON Data Type and Document StoreDave Stokes
 
Data manipulation and visualization in r 20190711 myanmarucsy
Data manipulation and visualization in r 20190711 myanmarucsyData manipulation and visualization in r 20190711 myanmarucsy
Data manipulation and visualization in r 20190711 myanmarucsySmartHinJ
 
Ufind proxo(cucurhatan).cfg
Ufind proxo(cucurhatan).cfgUfind proxo(cucurhatan).cfg
Ufind proxo(cucurhatan).cfgAhmad Hidayat
 
SunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQLSunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQLGabriela Ferrara
 
MongoDB World 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB World 2018: Tips and Tricks for Avoiding Common Query PitfallsMongoDB World 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB World 2018: Tips and Tricks for Avoiding Common Query PitfallsMongoDB
 
Permissions script for SQL Permissions
Permissions script for SQL PermissionsPermissions script for SQL Permissions
Permissions script for SQL PermissionsTobias Koprowski
 
MySQLConf2009: Taking ActiveRecord to the Next Level
MySQLConf2009: Taking ActiveRecord to the Next LevelMySQLConf2009: Taking ActiveRecord to the Next Level
MySQLConf2009: Taking ActiveRecord to the Next LevelBlythe Dunham
 
Tips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query PitfallsTips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query PitfallsMongoDB
 
機械学習モデルの判断根拠の説明
機械学習モデルの判断根拠の説明機械学習モデルの判断根拠の説明
機械学習モデルの判断根拠の説明Satoshi Hara
 
Firebase_not_really_yohoho
Firebase_not_really_yohohoFirebase_not_really_yohoho
Firebase_not_really_yohohoRoman Sachenko
 
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB .local Toronto 2019: Tips and Tricks for Effective IndexingMongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB .local Toronto 2019: Tips and Tricks for Effective IndexingMongoDB
 

Tendances (20)

Seistech SQL code
Seistech SQL codeSeistech SQL code
Seistech SQL code
 
Dipôles linéaires, régime transitoire
Dipôles linéaires, régime transitoireDipôles linéaires, régime transitoire
Dipôles linéaires, régime transitoire
 
Ecuacionesfuncionales2 1
Ecuacionesfuncionales2 1Ecuacionesfuncionales2 1
Ecuacionesfuncionales2 1
 
Ruby Language: Array, Hash and Iterators
Ruby Language: Array, Hash and IteratorsRuby Language: Array, Hash and Iterators
Ruby Language: Array, Hash and Iterators
 
MongoDB.local Seattle 2019: Tips & Tricks for Avoiding Common Query Pitfalls
MongoDB.local Seattle 2019: Tips & Tricks for Avoiding Common Query PitfallsMongoDB.local Seattle 2019: Tips & Tricks for Avoiding Common Query Pitfalls
MongoDB.local Seattle 2019: Tips & Tricks for Avoiding Common Query Pitfalls
 
Global Change, Species Diversity, and the Future of Marine Ecosystems
Global Change, Species Diversity, and the Future of Marine EcosystemsGlobal Change, Species Diversity, and the Future of Marine Ecosystems
Global Change, Species Diversity, and the Future of Marine Ecosystems
 
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
 
MySQL's JSON Data Type and Document Store
MySQL's JSON Data Type and Document StoreMySQL's JSON Data Type and Document Store
MySQL's JSON Data Type and Document Store
 
Data manipulation and visualization in r 20190711 myanmarucsy
Data manipulation and visualization in r 20190711 myanmarucsyData manipulation and visualization in r 20190711 myanmarucsy
Data manipulation and visualization in r 20190711 myanmarucsy
 
Ufind proxo(cucurhatan).cfg
Ufind proxo(cucurhatan).cfgUfind proxo(cucurhatan).cfg
Ufind proxo(cucurhatan).cfg
 
SunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQLSunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQL
 
New tags in html5
New tags in html5New tags in html5
New tags in html5
 
MongoDB World 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB World 2018: Tips and Tricks for Avoiding Common Query PitfallsMongoDB World 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB World 2018: Tips and Tricks for Avoiding Common Query Pitfalls
 
Permissions script for SQL Permissions
Permissions script for SQL PermissionsPermissions script for SQL Permissions
Permissions script for SQL Permissions
 
MySQLConf2009: Taking ActiveRecord to the Next Level
MySQLConf2009: Taking ActiveRecord to the Next LevelMySQLConf2009: Taking ActiveRecord to the Next Level
MySQLConf2009: Taking ActiveRecord to the Next Level
 
Tips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query PitfallsTips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query Pitfalls
 
機械学習モデルの判断根拠の説明
機械学習モデルの判断根拠の説明機械学習モデルの判断根拠の説明
機械学習モデルの判断根拠の説明
 
Avoid Query Pitfalls
Avoid Query PitfallsAvoid Query Pitfalls
Avoid Query Pitfalls
 
Firebase_not_really_yohoho
Firebase_not_really_yohohoFirebase_not_really_yohoho
Firebase_not_really_yohoho
 
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB .local Toronto 2019: Tips and Tricks for Effective IndexingMongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
 

En vedette

Listen&notifyとbwpの間違った使い方
Listen&notifyとbwpの間違った使い方Listen&notifyとbwpの間違った使い方
Listen&notifyとbwpの間違った使い方Toshi Harada
 
Integrating PostgreSql with RabbitMQ
Integrating PostgreSql with RabbitMQIntegrating PostgreSql with RabbitMQ
Integrating PostgreSql with RabbitMQGavin Roy
 
Go meetup smotri+ 23.04.2015
Go meetup smotri+ 23.04.2015Go meetup smotri+ 23.04.2015
Go meetup smotri+ 23.04.2015Mikhail Salosin
 
Android & PostgreSQL
Android & PostgreSQLAndroid & PostgreSQL
Android & PostgreSQLMark Wong
 
Data Processing Inside PostgreSQL
Data Processing Inside PostgreSQLData Processing Inside PostgreSQL
Data Processing Inside PostgreSQLEDB
 

En vedette (7)

Listen&notifyとbwpの間違った使い方
Listen&notifyとbwpの間違った使い方Listen&notifyとbwpの間違った使い方
Listen&notifyとbwpの間違った使い方
 
Go meetup 2015 04-23
Go meetup 2015 04-23Go meetup 2015 04-23
Go meetup 2015 04-23
 
PostgreSQL: meet your queue
PostgreSQL: meet your queuePostgreSQL: meet your queue
PostgreSQL: meet your queue
 
Integrating PostgreSql with RabbitMQ
Integrating PostgreSql with RabbitMQIntegrating PostgreSql with RabbitMQ
Integrating PostgreSql with RabbitMQ
 
Go meetup smotri+ 23.04.2015
Go meetup smotri+ 23.04.2015Go meetup smotri+ 23.04.2015
Go meetup smotri+ 23.04.2015
 
Android & PostgreSQL
Android & PostgreSQLAndroid & PostgreSQL
Android & PostgreSQL
 
Data Processing Inside PostgreSQL
Data Processing Inside PostgreSQLData Processing Inside PostgreSQL
Data Processing Inside PostgreSQL
 

Similaire à Heroku Waza 2013 Lessons Learned

Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQLJussi Pohjolainen
 
Coding Horrors
Coding HorrorsCoding Horrors
Coding HorrorsMark Baker
 
Building advanced data-driven applications
Building advanced data-driven applicationsBuilding advanced data-driven applications
Building advanced data-driven applicationsMariaDB plc
 
Onde mora a produtividade do Ruby on Rails?
Onde mora a produtividade do Ruby on Rails?Onde mora a produtividade do Ruby on Rails?
Onde mora a produtividade do Ruby on Rails?Fabio Kung
 
DevOpsDaysRiga 2018: Michiel Rook - Database schema migrations with zero down...
DevOpsDaysRiga 2018: Michiel Rook - Database schema migrations with zero down...DevOpsDaysRiga 2018: Michiel Rook - Database schema migrations with zero down...
DevOpsDaysRiga 2018: Michiel Rook - Database schema migrations with zero down...DevOpsDays Riga
 
Eve - REST API for Humans™
Eve - REST API for Humans™Eve - REST API for Humans™
Eve - REST API for Humans™Nicola Iarocci
 
07 application security fundamentals - part 2 - security mechanisms - data ...
07   application security fundamentals - part 2 - security mechanisms - data ...07   application security fundamentals - part 2 - security mechanisms - data ...
07 application security fundamentals - part 2 - security mechanisms - data ...appsec
 
MySQL server security
MySQL server securityMySQL server security
MySQL server securityDamien Seguy
 
The Inside Scoop on Neo4j: Meet the Builders
The Inside Scoop on Neo4j: Meet the BuildersThe Inside Scoop on Neo4j: Meet the Builders
The Inside Scoop on Neo4j: Meet the BuildersNeo4j
 
IBM Insight 2015 - 1824 - Using Bluemix and dashDB for Twitter Analysis
IBM Insight 2015 - 1824 - Using Bluemix and dashDB for Twitter AnalysisIBM Insight 2015 - 1824 - Using Bluemix and dashDB for Twitter Analysis
IBM Insight 2015 - 1824 - Using Bluemix and dashDB for Twitter AnalysisTorsten Steinbach
 
Web API Filtering - Challenges, Approaches, and a New Tool
Web API Filtering - Challenges, Approaches, and a New ToolWeb API Filtering - Challenges, Approaches, and a New Tool
Web API Filtering - Challenges, Approaches, and a New ToolDaniel Fields
 
4 execution plans
4 execution plans4 execution plans
4 execution plansRam Kedem
 
BigQuery implementation
BigQuery implementationBigQuery implementation
BigQuery implementationSimon Su
 
PesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShell
PesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShellPesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShell
PesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShellDaniel Bohannon
 

Similaire à Heroku Waza 2013 Lessons Learned (20)

Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQL
 
Coding Horrors
Coding HorrorsCoding Horrors
Coding Horrors
 
Building advanced data-driven applications
Building advanced data-driven applicationsBuilding advanced data-driven applications
Building advanced data-driven applications
 
Onde mora a produtividade do Ruby on Rails?
Onde mora a produtividade do Ruby on Rails?Onde mora a produtividade do Ruby on Rails?
Onde mora a produtividade do Ruby on Rails?
 
DevOpsDaysRiga 2018: Michiel Rook - Database schema migrations with zero down...
DevOpsDaysRiga 2018: Michiel Rook - Database schema migrations with zero down...DevOpsDaysRiga 2018: Michiel Rook - Database schema migrations with zero down...
DevOpsDaysRiga 2018: Michiel Rook - Database schema migrations with zero down...
 
Pets and Pandas.
Pets and Pandas.Pets and Pandas.
Pets and Pandas.
 
Real
RealReal
Real
 
Eve - REST API for Humans™
Eve - REST API for Humans™Eve - REST API for Humans™
Eve - REST API for Humans™
 
07 application security fundamentals - part 2 - security mechanisms - data ...
07   application security fundamentals - part 2 - security mechanisms - data ...07   application security fundamentals - part 2 - security mechanisms - data ...
07 application security fundamentals - part 2 - security mechanisms - data ...
 
MySQL server security
MySQL server securityMySQL server security
MySQL server security
 
The Inside Scoop on Neo4j: Meet the Builders
The Inside Scoop on Neo4j: Meet the BuildersThe Inside Scoop on Neo4j: Meet the Builders
The Inside Scoop on Neo4j: Meet the Builders
 
REST
RESTREST
REST
 
Czzawk
CzzawkCzzawk
Czzawk
 
IBM Insight 2015 - 1824 - Using Bluemix and dashDB for Twitter Analysis
IBM Insight 2015 - 1824 - Using Bluemix and dashDB for Twitter AnalysisIBM Insight 2015 - 1824 - Using Bluemix and dashDB for Twitter Analysis
IBM Insight 2015 - 1824 - Using Bluemix and dashDB for Twitter Analysis
 
Web API Filtering - Challenges, Approaches, and a New Tool
Web API Filtering - Challenges, Approaches, and a New ToolWeb API Filtering - Challenges, Approaches, and a New Tool
Web API Filtering - Challenges, Approaches, and a New Tool
 
DBAccess 研究
DBAccess 研究DBAccess 研究
DBAccess 研究
 
4 execution plans
4 execution plans4 execution plans
4 execution plans
 
BigQuery implementation
BigQuery implementationBigQuery implementation
BigQuery implementation
 
Curso de MySQL 5.7
Curso de MySQL 5.7Curso de MySQL 5.7
Curso de MySQL 5.7
 
PesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShell
PesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShellPesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShell
PesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShell
 

Heroku Waza 2013 Lessons Learned

  • 1. Heroku waza 2013 Lessons Learned Simon Bagreev Twitter: @status_200 Github: semmin
  • 2. I attended Keynote - Michael Lopp • Why Python, Ruby and Javascript are Slow - Alex Gaynor • Heroku Secrets - Noah Zoske • API VS Game: Fight! - Wesley Beary • Predictable Failure - Ryan Smith • Postgres: The bits you haven’t found - Peter Van Hardenberg • Mobile is Not Different - Matt Thompson • Everything is a Remix - Kirby Ferguson
  • 3. liked the most • Keynote - Michael Lopp • Why Python, Ruby and Javascript are Slow - Alex Gaynor • Heroku Secrets - Noah Zoske • API VS Game: Fight! - Wesley Beary • Predictable Failure - Ryan Smith • Postgres: The bits you haven’t found - Peter Van Hardenberg • Mobile is Not Different - Matt Thompson • Everything is a Remix - Kirby Ferguson
  • 4. postgres: 12 bits you haven’t found Made me realize
  • 5. postgres: 12 bits you haven’t found • psql -- postgres console -- very powerful • need to upgrade to 9.2 • tons of tools, extensions, types • tools for monitoring, BI
  • 6. WITH operator Auxiliary statements for use in larger queries WITH status_with_next AS ( SELECT *, lead(state, 1) OVER (partition by agent_uuid order by time) as next from agent_statuses ), oops AS ( SELECT * from status_with_next WHERE state = 'training' and next = 'captured' ) SELECT name, count(*) as training_captures from oops join agents on agents.uuid = agent_uuid GROUP BY name ORDER by training_captures DESC;
  • 7. ARRAys -- create CREATE TABLE jobseekers ( email text, industries integer[], ... ); -- insert INSERT INTO jobseekers(email, zip, industries, source, created_at, updated_at) VALUES (' sbagreev@gmail.com', '23453', '{1,2,3}', 'EG', now(), now()); INSERT INTO jobseekers(email, zip, industries, source, created_at, updated_at) VALUES ('simon.bagreev@gmail.com', '23453', '{4,5,6}', 'EG', now(), now()); -- query by inclusion @> SELECT email FROM jobseekers WHERE industries @> ARRAY[3,1]; -- > sbagreev@gmail.com -- query by intersection && SELECT email FROM jobseekers WHERE industries && ARRAY[4]; -- > simon.bagreev@gmail.com
  • 8. dblink Connect to other Postgres Databases -- add extension CREATE EXTENSION dblink; -- connect to the external database SELECT dblink_connect('quasar_connection','dbname=quasar_development'); dblink_connect ---------------- OK (1 row) -- query remote database SELECT * FROM dblink('quasar_connection', 'select id, email from users') AS quasar_users(id int, email varchar(255)); id | email ----+---------------------------------------- 24 | user1@gmail.com 23 | sbagreev@gmail.com 29 | simon.bagreev@gmail.com 25 | user5@employmentguide.com
  • 9. listen / notify Postgres’ own queueing, used to send notifications to clients -- create listener LISTEN USER_UPDATES; /* send notification to listeners can be done from trigger */ NOTIFY USER_UPDATES, 'User with id=23 just changed email'; -- on the listener Asynchronous notification "user_updates" with payload "User with id=23 just changed email" received from server process with PID 81016.
  • 10. regexes -- pattern matching SELECT 'foo bar baz' ~ 's+baz' as matches_pattern; -- search and replace UPDATE jobseekers SET zip = regexp_replace(zip, '23', '45'); SELECT zip FROM jobseekers; zip ------- 45451 45451
  • 11. -- add extension UUIDs CREATE EXTENSION "uuid-ossp"; -- create table with uuid as PK CREATE TABLE t (uuid uuid PRIMARY KEY DEFAULT uuid_generate_v4(), name text); d t Table "public.t" Column | Type | Modifiers --------+------+------------------------------------- uuid | uuid | not null default uuid_generate_v4() name | text | INSERT INTO t(name) VALUES ('foo'); SELECT * FROM t; uuid | name --------------------------------------+------ 7f7941f3-6705-4c28-8028-d1ee5e8d3b8b | foo
  • 12. -- add extension hstore !!! CREATE EXTENSION hstore; -- create applications table with custom attributes CREATE TABLE job_applications(uuid uuid PRIMARY KEY DEFAULT uuid_generate_v4(), attrs hstore, company_id integer); -- company 1 wants only name and email in their applications INSERT INTO job_applications (company_id, attrs) VALUES (1, 'name => "Simon Bagreev", email => " sbagreev@gmail.com"'); -- company 2 also wants address INSERT INTO job_applications (company_id, attrs) VALUES (2, 'name => "Simon Bagreev", email => "sbagreev@gmail.com", address => "123 Broadwalk St"'); -- company 3 wants phone number too INSERT INTO job_applications (company_id, attrs) VALUES (3, 'name => "Simon Bagreev", email => "sbagreev@gmail.com", address => "123 Broadwalk St", phone => "7570000000"'); SELECT * from job_applications; attrs | company_id -------------------------------------------------------------------------------------------------------------+------------ "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com" | 1 "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com", "address"=>"123 Broadwalk St" | 2 "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com", "phone"=>"7570000000", "address"=>"123 Broadwalk St"| 3
  • 13. hstore Can add / delete keys -- company 1 decides to add a phone number to the app UPDATE job_applications SET attrs = attrs || 'phone=>7573518500'::hstore WHERE company_id=1; SELECT attrs, company_id FROM job_applications; attrs | company_id -------------------------------------------------------------------------------------------------------------+------------ "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com", "address"=>"123 Broadwalk St" | 2 "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com", "phone"=>"7570000000", "address"=>"123 Broadwalk St"| 3 "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com", "phone"=>"7570000000" | 1
  • 14. hstore Querying -- what companies are using address on their application? SELECT attrs, company_id FROM job_applications WHERE attrs ? 'address'; attrs | company_id -------------------------------------------------------------------------------------------------------------+------------ "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com", "address"=>"123 Broadwalk St" | 2 "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com", "phone"=>"7573518500", "address"=>"123 Broadwalk St" | 3 -- find all applicants with address 123 Broadwalk SELECT attrs, company_id FROM job_applications WHERE attrs @> 'address=>"123 Broadwalk St"'::hstore; attrs | company_id -------------------------------------------------------------------------------------------------------------+------------ "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com", "address"=>"123 Broadwalk St" | 2 "name"=>"Simon Bagreev", "email"=>"sbagreev@gmail.com", "phone"=>"7573518500", "address"=>"123 Broadwalk St" | 3
  • 15. HSTore • can be indexed • searchable
  • 16. postgres has more to offer • full-text search • TOAST - store large values • pgcrypto - encryption for your DB • pg_stat_activity, pg_stat_statements - stats • postGIS - geographical awesomeness • JSON and PL/V8 -- schemaless SQL
  • 17. heroku secrets presentation • use --version=9.2 flag when adding Postgres addon on Heroku • encrypt your app’s config, store it on AWS • use multi-processed and multi-threaded servers • dataclips! - read-only, easy-to-share quick database queries, exportable to many formats, can export data to Google docs
  • 18. Before / After Questions I had going there: • Q: Want to hear more explanations about recent “dumb routing issue”, and suggestions from Heroku to make it “smarter”, especially on Cedar stack. • A: Doesn’t affect Cedar multi-threaded environment • Q: Want to learn more about multi-threading and multi-processing on Heroku (does it make sense to do it in Rails/Heroku? If so, how?). • A: Unicorn for multi-process, JRuby + JVM for multi-threading • Q: When is Rails 4.0 / Ruby 2.0 will be officially supported by Heroku? • A: Already is. • Q: Will Heroku support multiple availability zones (US-West, Asia)? • A: In Beta (US West, EU)
  • 19. Before / After Questions I had going there: • Q: Will the SLA (99.99% uptime) be improved any time soon? • A: Constantly working on it • Q: Want learn more tricks for increasing performance on Heroku, and running large enterprise- scale applications. • A: Many-many options