Skip to content

Instantly share code, notes, and snippets.

View tierra's full-sized avatar

Bryan Petty tierra

View GitHub Profile
Elastic Beanstalk (2011)
- EC2 / ASG based deployments
CloudFormation (2011)
- Designed for infrastructure management, but can be used for deployments too.
OpsWorks (2013)
- Infrastructure automation
CodeDeploy (2014)
10:30 -ChanServ(ChanServ@services.)- Entry Nickname/Host Flags |
10:30 -ChanServ(ChanServ@services.)- ----- ---------------------- ----- |
10:30 -ChanServ(ChanServ@services.)- 1 raboof +AFRefiorstv (founder) (#wxwidgets) [modified ? ago, on Jan 01 00:00:00 1970] |
10:30 -ChanServ(ChanServ@services.)- 2 BrianHV +AFRefiorstv (founder) (#wxwidgets) [modified 12y 26w 2d ago, on Nov 18 21:50:41 2008]
ActiveSupport::Notifications.subscribe("sql.active_record") do |_, _, _, _, details|
if details[:sql] =~ /search_path/
puts details[:sql]
puts caller.join("\n")
puts "*" * 50
end
end
[15] pry(#<RSpec::ExampleGroups::SwitchmanActiveRecordConnectionPool>)> @conn.execute 'SELECT 1'
=> #<PG::Result:0x00000000047e2120 status=PGRES_TUPLES_OK ntuples=1 nfields=1 cmd_tuples=1>
[16] pry(#<RSpec::ExampleGroups::SwitchmanActiveRecordConnectionPool>)> @conn.active?
=> true
[17] pry(#<RSpec::ExampleGroups::SwitchmanActiveRecordConnectionPool>)> @conn.execute 'SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid = pg_backend_pid()'
ActiveRecord::StatementInvalid: PG::UnableToSend: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
: SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid = pg_backend_pid()
from /home/docker/.rvm/gems/ruby-2.3.6/gems/activerecord-5.0.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `async_exec'
Document Size Limits:
DynamoDB: 400 KB
Datastore: 1 MB
CosmosDB: 2 MB
MongoDB: 16 MB
CouchDB: 20 MB
Cassandra: 2 GB (roughly several MB recommended)
RethinkDB: none (16 MB recommended)

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@tierra
tierra / .dockerignore
Last active February 15, 2016 05:45
Modern phpBB Docker Configuration
.dockerignore
Dockerfile
docker-compose.yml
.git
.gitignore
@tierra
tierra / gist:645a5c9d905de44f6ff0
Created November 1, 2015 06:19
Five days of wxWidgets 3.0.2 downloads off of GitHub
bryan@ibaku:~$ ruby wx-downloads.rb
changes.txt: 3, 670 KB
README.md: 16, 110 KB
wxMSW-3.0.2-Setup.exe: 834, 37 GB
wxMSW-3.0.2_gcc471TDM_Dev.7z: 9, 350 MB
wxMSW-3.0.2_gcc471TDM_ReleaseDLL.7z: 14, 82 MB
wxMSW-3.0.2_gcc471TDM_x64_Dev.7z: 13, 660 MB
wxMSW-3.0.2_gcc471TDM_x64_ReleaseDLL.7z: 7, 75 MB
wxMSW-3.0.2_gcc481TDM_Dev.7z: 25, 960 MB
wxMSW-3.0.2_gcc481TDM_ReleaseDLL.7z: 19, 110 MB
@tierra
tierra / create_releases.sh
Created October 25, 2015 20:16
Script used to create and upload existing wxWidgets releases to GitHub
#!/bin/bash
# You must generate a personal access token with public_repo
# permission, and configure that token using the following:
# export GITHUB_TOKEN="..."
GITHUB_USER="wxWidgets"
GITHUB_REPO="wxWidgets"
for directory in v*/; do
@tierra
tierra / retag-wx.sh
Created October 23, 2015 00:58
Script used to create v* tags for wxWidgets.
#!/bin/bash
for t in $(git tag -l | grep -v '@' | egrep '^(WX_[23]_[0-9]_[0-9])'); do
export GIT_COMMITTER_DATE=$(git log -1 --format=%ad $(echo $t))
VTAG=$(echo $t | sed -e 's/WX_2_4_0_CANDIDATE/WX_2_4_0-rc1/;s/2rc/2-rc/;s/_rc/-rc/;s/^WX_/v/;s/_/\./g;')
echo "Tagging $t as $VTAG with $GIT_COMMITTER_DATE"
git tag -m "Release $VTAG." $VTAG $t;
done