wordpress高速化メモ
ざっと調べてみた。前提としてaws環境を使用。
Wordpress自体を高速化する
カリカリにチューニングされた状態でAMIが公開されている様子。let's encryptなど必要になりそうなものが諸々入っているので、1から作る場合やガッと移行できそうなら良さそう。ページキャッシュ機能付き。
仮想マシン構成
・WordPress 最新版(KUSANAGI 専用プラグイン同梱)
・CentOS 7
・Nginx 1.9
・Apache 2.4
・HHVM 3.11
・PHP 7.0(php-fpm, Cli)
・PHP 5.6(php-fpm, Cli)
・MariaDB Galera Server 10.0
※PHP7.0の利用は、WordPress4.4以上、および対応プラグインが必須です。
CloudFrontを前段に置く
CloudFront as Reverse Proxyという構成らしい。nginxとかvarnish置かなくていいのかー。素晴らしい。
パフォーマンス監視
NewRelicいれてBefore/Afterでプロダクション環境のパフォーマンスがこんなに改善されましたよー、と分かるように。無料プラン内で十分使える。
golangからcloudsearchを使う
sdk install
go get github.com/aws/aws-sdk-go/...
example code
package main import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudsearchdomain" ) func main() { svc := cloudsearchdomain.New(session.New(&aws.Config{ Region: aws.String("ap-northeast-1"), Endpoint: aws.String("http://search-XXXX.ap-northeast-1.cloudsearch.amazonaws.com"), })) params := &cloudsearchdomain.SearchInput{ Query: aws.String("Iron Man 2"), } resp, err := svc.Search(params) if err != nil { fmt.Println(err.Error()) return } fmt.Println(resp) }
run
go run cloudsearch.go { Hits: { Found: 1, Hit: [{ Fields: { running_time_secs: ["7440"], image_url: ["http://ia.media-imdb.com/images/M/MV5BMTM0MDgwNjMyMl5BMl5BanBnXkFtZTcwNTg3NzAzMw@@._V1_SX400_.jpg"], rank: ["276"], directors: ["Jon Favreau"], actors: ["Robert Downey Jr.","Mickey Rourke","Gwyneth Paltrow"], rating: ["7.0"], genres: ["Action","Adventure","Sci-Fi"], plot: ["Tony Stark has declared himself Iron Man and installed world peace... or so he thinks. He soon realizes that not only is there a mad man out to kill him with his own technology, but there's something more: he is dying."], title: ["Iron Man 2"], year: ["2010"], release_date: ["2010-04-26T00:00:00Z"] }, Id: "tt1228705" }], Start: 0 }, Status: { Rid: "uZ/D68sqFQp5O20=", Timems: 12 } }
golangのinterface
package main import "fmt" func main() { var repo UserRepository repo = NewUserRepositoryDB() user := repo.Resolve(1) fmt.Println("user:", user) user.Name = "ChangedName" repo.Save(user) } type User struct { ID int64 Name string } type UserRepository interface { Save(user User) Resolve(id int64) User } type UserRepositoryDB struct{} func NewUserRepositoryDB() UserRepositoryDB{ return UserRepositoryDB{} } func (this UserRepositoryDB) Save(user User) { fmt.Println("[call] save:", user) } func (this UserRepositoryDB) Resolve(id int64) User { fmt.Println("[call] resolve:", id) return User{id, "user"} }
実行
$ go run hoge.go [call] resolve: 1 user: {1 user} [call] save: {1 ChangedName}
HogeRepositoryでInterface切って、実装クラスはDIできるようにすると捗りそう。
ITP1_2 Branch on Condition
この本、kindleセールの時に買ってみた。
初歩の本だったみたい。けどスラスラ読み進められて楽しい。
C++のiostreamすげー便利。
ScalaでStdIn.readlineを連発するより簡単に標準入力を取り込めるので、プロコン的な奴で便利な気がした。
長方形の中の円 | プログラミング入門 | Aizu Online Judge
#include<iostream> using namespace std; // ITP1_2 Branch on Condition // D: A Circle in a Rectangle int main() { int W, H, x, y, r; cin >> W >> H >> x >> y >> r; bool isOver = false; // X軸 if (x - r < 0) isOver = true; if (W < x + r) isOver = true; // Y軸 if (y - r < 0) isOver = true; if (H < y + r) isOver = true; if (!isOver) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
カジュアルにlivereload
軽くHTMLをコーディングしたかった。
ライブリロードしたいけどgulp使ったりザ・フロントエンドみたいなことはしたくない…
goemon使ってみよーと思ったら超簡単だった。
goemon -g > goemon.yml # pathとか修正 vim goemon.yml echo '<script src="http://localhost:35730/livereload.js"></script>' > index.html goemon -- open index.html #ファイルを変更したらライブリロードされる echo "hello world" >> index.html
はかどる
memcachedコードリーディング(1)
memcachedをコード・リーディングしてみることにした。
まずはgithubからコードを取得し、はじめのコミットに戻りコンパイルしてみるところまで。
# コード取得 git clone git@github.com:memcached/memcached.git cd memcached # first commit まで戻る git reset --hard 32f382b605b4565bddfae5c9d082af3bfd30cf02 # ライブラリインストール brew install libevent brew install judy # -staticオプションはcrt0.oがないyoと怒られるので外す gcc -g -I. -L. -o memcached-debug memcached.c -levent -lJudy
gcc-2.95でコンパイルされることを前提にしたコードのようで、返り値にintが定義された関数のreturnで0を省略するとコンパイルエラーになってしまう。微修正。
git diff diff --git a/memcached.c b/memcached.c index 8ba15e9..d1e9fc2 100644 --- a/memcached.c +++ b/memcached.c @@ -758,7 +758,7 @@ int try_read_network(conn *c) { int update_event(conn *c, int new_flags) { if (c->ev_flags == new_flags) - return; + return 1; if (event_del(&c->event) == -1) return 0; event_set(&c->event, c->sfd, new_flags, event_handler, (void *)c); c->ev_flags = new_flags; @@ -1190,6 +1190,6 @@ int main (int argc, char **argv) { /* enter the loop */ event_loop(0); - return; + return 1; }
telnetでつなぐ
$ telnet 127.0.0.1 11211 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. set hoge 0 0 3 foo STORED get hoge VALUE hoge 0 3 foo END stats cachedump 13 1000 ITEM hoge [3 b; 1461908919 s] END
動いとる^^