- GoogleのSRE: 最適化に時間を使う
- コンピューティングリソースだけでなく、時間の使い方も最適化する
- トイルに時間を使いたくない
- トイルに関する包括的な話はSRE本の5章参照
- この章でのトイルの定義:
- サービス維持に関するもので、繰り返され、予測可能な一連のタスク
- 本番運用にトイルは避けられない
インスタンスの起動スクリプトとかを書いてるときによく欲しいと思うやつです。
例えば、 service nginx start
が実行されたあとに curl -i localhost | grep "200 OK"
とかをすると、サービスがそれなりに動いていることが確認できてよかったりするのですが、あまりにも直後だとサーバの起動が間に合わず、curl が失敗してしまいます。nginxだとまだましだけど、アプリケーションサーバだとそれなりに時間がかかったりする。
古典的な解決方法は、 sleep 30
です。簡単だけど、アプリケーションが巨大になってくると30秒では起動しないこともある。じゃぁ sleep 60
が妥当か?でも、サーバインスタンスの起動スクリプト全体はできるだけ早く立ち上がってほしい。困った。
なので、curlが成功するまで叩き続ける、みたいなスクリプトに仕上げたくなるわけです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: A faster load_textdomain | |
Version: 0.0.1 | |
Description: While we're wating for https://core.trac.wordpress.org/ticket/32052. | |
Author: Per Soderlind | |
Author URI: https://soderlind.no | |
Plugin URI: https://gist.github.com/soderlind/610a9b24dbf95a678c3e | |
License: GPL |
When working with API clients there are several distinct areas of concern. Each of these happen in sequence and are used with the goal of receiving a Domain Model at the end.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- check_pg_settings.sql | |
-- | |
-- Copyright(C) 2012 Uptime Technologies, LLC. All rights reserved. | |
-- | |
SELECT name, | |
setting, | |
CASE WHEN setting::integer = 4096 THEN 'WARNING: default value (4096=32MB) is too small.' | |
WHEN setting::integer < 65536 THEN 'WARNING: too small. (<65536=512MB)' | |
ELSE 'OK.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"log" | |
"net/http" | |
"os" | |
) |