フィーチャー開発から ホールプロダクト開発へ ~ 顧客価値へ向き合い続ける挑戦 ~ @itohiro73 #開発生産性con_findy
フィーチャー開発から ホールプロダクト開発へ ~ 顧客価値へ向き合い続ける挑戦 ~ @itohiro73 #開発生産性con_findy
こんにちは、ピクスタ開発部の星直史です id:watasihasitujidesu です。 idがwatasihasitujidesuですけど、執事ではありません。エンジニアです。 今日は、タイトルの通り、ActiveRecordが提供するeager_loadとpreloadを使い、データ取得時間を60%高速化したときの話をします。 目次 要件 修正前のコード 処理が遅い原因 対応方針 修正後のコード まとめ 要件 このブログ投稿時点で、ピクスタで販売している素材点数は1500万点を越えています。 検索データはAWS CloudSearchに格納しており、全素材のDocumentを更新すると膨大な時間(約2週間)がかかっていました。 このまま素材点数が増え続けた場合、データ更新時間も線形的に長くなり、気軽に更新ができなくなってしまうため、 処理時間の高速化する必要が出てきました。 また、メ
Railsで中規模なサイトを作っていく上で 避けて通れないのが、増えてきたモデルを適切にキャッシュするしくみのように思えます。 特に変更が少ないマスタ的なテーブルに対して、『多対多』で関連付け(アソシエーション: association)がある場合などは、 それなりのSQLの発行コストになることがあります。そこを適切にキャッシュすることでDBへの負荷が減り、 ユーザーへのレスポンスが改善されると思います。 今回は、最近実装しているキャッシュの方法について、紹介したいと思います。 (というか偉い人、ぜひいい方法教えてください><) 🍣 前提条件: RailsからRedisにキャッシュ今回は前提条件として、Railsのアプリケーションから『redis-store/redis-rails - GitHub』 のGemを使って、Redisにキャッシュをされているとします。 セットアップ方法は『r
Here at Plataformatec we use Github Pull Requests a lot for code review and this usually yields tons of constructive comments and excellent discussions from time to time. One of the recent topics was about whether we should use scopes or class methods throughout the project to be consistent. It’s also not hard to find discussions about it all over the internet. The classic comment usually boils do
Arel is the kind of library that many of us Rails developers use on a daily basis and might not even know about it. So what's this library whose name only pops up when everything else fails all about? It's all about providing frameworks with a way of building and representing SQL queries. It's not the kind of library you would typically want to use directly (although you could as shown in a minute
Railsでプログラムを書いるとSQLを直接記述する機会が意外と多いので、 なるべくRubyらしく書く方法がないか調べてみました。 ORなどかなり基本的な構文でもarel_tableを使う必要があるのですね。 というわけで、Arel::Table を使ってみました。 動作確認環境は以下の通りです。 ruby: 1.9.3-p392 Rails: 3.2.13 arel: 3.0.2 MySQL: 5.1.65 検索条件をORで繋げたい 基本的な構文ですがSQLを直接記述する場合が多いのではないでしょうか? User.where("name = ? OR name = ?", "太郎", "花子").to_sql #=> "SELECT `users`.* FROM `users` WHERE (name = '太郎' OR name = '花子')" なるべくRubyで書こうとするとこうな
もう数ヶ月くらい前になるけど Rails (ActiveRecord) で R/W splitting を行う switch_point という gem を書いた。 Rails アップグレード作業の中で、魔改造された acts_as_readonlyable をメンテすることに嫌気がさして、もっとマシな実装方法があるはずと思って勢いでコアの実装をして、それから実際のアプリケーションに組み込んで本番に投入していきながら機能追加やバグ修正を重ねて今の形になった。 先日の RubyKaigi 2014 の LT で、R/W Splitting in Rails というタイトルで switch_point の紹介をした。 今まで使い方を真面目に書いてなかったけど、LT 内で軽く紹介しつつ会期中に典型的な使い方を README に書いた。メソッドやクラスのドキュメントは全然書いてない (要るのかな…
おおいしつかさ 旅行とバイクとドライブと料理と宇宙が好き。 Ubie Discoveryのプログラマ。 関連 : RailsでMysqlスレーブ群をロードバランサ経由で使用できる、FreshConnectionを作り始めました RailsのActiveRecordは、DBとのコネクションがプールされます。 アクセスごとにコネクションをはりなおすよりは、オーバーヘッドがない分、理にかなっているようにも思えます。 ただ、比較的大きめなサイトになってくると、はりっぱなしのコネクションが多くなりすぎちゃって大変なことになってきます(1サーバ1万コネクションとかなりかねない)。リソースは食うし、たくさんのスレーブを抱えているときにActsAsReadonlyableなどでちまちまやっていたらとても運用できません。スレーブなんてLVS+keepalivedでバランシングしちゃいたいところ。でもコネクシ
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く