TIL, 2018-06-03, Sharding, Read/Write Databases
Research on Sharding, Reading Octopus
- If you have
HashWithIndifferentAccess, just use it?
MINORis a thing to check versions.
- Logger method:
def self.logger if defined?(Rails.logger) @logger ||= Rails.logger else @logger ||= Logger.new($stderr) end end
- Hooks into
ActiveRecord::Base.connection, creates an
- Inclusion method:
def self.included(base) base.extend(ClassMethods) end
How would I implement separate databases for reading and writing operations?
- Read/write master databases and read-only slaves are a common pattern, especially for big applications doing mostly read accesses/data warehouses.
- It allows you to scale and to tune the databases differently, for either efficient reads or efficient writes.
- It really depends on what you are trying to achieve by having two databases.
- If it is for performance reasons (which i suspect it may be) i would suggest you look into denormalizing the read-only database as needed for performance.
- If performance isn’t an issue then I wouldn’t mess with the read-only schema.
- I’ve worked on similar systems where there would be a read/write database that was only lightly used by administrative users. That database would then be replicated to the read only database during a nightly process.
Slow Rails Queries
- New Relic,
PgHeroto track down query bottlenecks in the applications.
Seq Scans: Means PG needs to scan a table row by row to find matching entries.
- Seed local database to mimic production. Perform benchmarks on a local computer, with settings resembling a real production site.
- Siege for local benchmarks.
- Bootstrap 4 File Input: I fixed this with JQuery.
- Capybara upload file: Use
- You need
type: featureto enable Capybara methods (RSpec).
- When creating an index over multiple columns, put the column with least variance first.
- Getting a file’s MIME type using Rack.
- Apparently you shouldn’t offset when using an index?
Musings NoSQL Replacing RDBMS? Computed relational join is important! App-side joins are bad performance-wise. Convergence: RDBMSes are adding JSON support,...