Skip to content

Instantly share code, notes, and snippets.

@kitak
kitak / doc.md
Last active October 18, 2023 09:57
コマンドによる「負荷」の原因切り分け

コマンドによる「負荷」の原因切り分け

この文章では、Linuxコマンド、sar, top, psを使って、一般的に負荷といわれるものの原因を切り分けることを目的とする。

そもそも負荷とは

「複数のタスクによるサーバリソースの奪い合いの結果に生じる待ち時間」を一言で表した言葉。OSのチューニングとは負荷の原因を知り、それを取り除くことにほかならない。

ボトルネックの見極め作業の大まかな流れ

  • ロードアベレージ(処理を実行したくても、実行できなくて待たされているプロセス(CPUの実行権限が与えられるのを待っている、またはディスクI/Oが完了するのを待っている)の数)を見る
@kitak
kitak / getRelativeTime.js
Created April 27, 2013 09:14
JSでお手軽に相対時刻を吐き出す
function getRelativeTime(baseDateStr, targetDateStr){
var baseDate = new Date(baseDateStr);
var targetDate = new Date(targetDateStr);
var elapsedTime = Math.ceil((baseDate.getTime() - targetDate.getTime())/1000);
var message = null;
// これ以下で一定時間未満のごとのメッセージの表示方法を条件分岐
@kitak
kitak / gist:5974526
Last active March 27, 2019 13:13
KVS導入(ダイレクトルーティング)
# lb001.kitak.pbでの操作
sudo yum install ipvsadm
sudo chkconfig --add ipvsadm
sudo chkconfig ipvsadm on
sudo su - -c 'echo "1" > /proc/sys/net/ipv4/ip_forward'
sudo ifconfig eth0:0 192.168.46.30 netmask 255.255.255.0
sudo vi /etc/sysconfig/network-scripts/ifconfig-eth0 #次回起動時も有効にする
sudo ipvsadm -A -t 192.168.46.30:80 -s rr # 転送元のIPアドレス、ポート
sudo ipvsadm -a -t 192.168.46.30:80 -r 192.168.46.83:80 -g # 転送先のIPアドレス、ポート
sudo ipvsadm -Ln # 確認
@kitak
kitak / Vagrantfile
Last active January 22, 2019 01:11
ESの素振り
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
@kitak
kitak / testing_front_end_rspec_capybara.md
Created July 10, 2012 11:08 — forked from juliocesar/testing_front_end_rspec_capybara.md
Testing front-end for a Sinatra app with RSpec and Capybara

Testing front-end for a Sinatra app with RSpec and Capybara

I've used Cucumber quite a bit on my last job. It's an excellent tool, and I believe readable tests are the way to the future. But I could never get around to write effective scenarios, or maintain the boatload of text that the suite becomes once you get to a point where you have decent coverage. On top of that, it didn't seem to take much for the suite to become really slow as tests were added.

A while ago I've seen a gist by Lachie Cox where he shows how to use RSpec and Capybara to do front-end tests. That sounded perfect for me. I love RSpec, I can write my own matchers when I need them with little code, and it reads damn nicely.

So for my Rails Rumble 2010 project, as usual, I rolled a Sinatra app and figured I should give the idea a shot. Below are my findings.

Gemfile

/*
export interface GridArray<T> extends Array<T> {
first?(): T;
}
export interface Table<T> {
select(filter: object): GridArray<T>;
}
*/
/*
export interface GridArray<T> extends Array<T> {
first?(): T;
}
export interface Table<T> {
select(filter: object): GridArray<T>;
}
*/
@kitak
kitak / question_promisify.js
Last active January 29, 2018 01:08
question promisify
const readline = require('readline')
const util = require('util')
const rl = readline.createInterface({input: process.stdin, output: process.stdout})
rl.question[util.promisify.custom] = (arg) => {
return new Promise((resolve) => {
rl.question(arg, resolve);
});
};
const questionPromise = util.promisify(rl.question);
questionPromise('What do you think of Node.js? ').then((answer) => {
@kitak
kitak / gist:6372481
Last active May 17, 2017 21:54
MySQLのreconnectについて

MySQLのreconnectとは

mysqlクライントでのreconnect

mysqlクライアントがステートメントの送信中にサーバとの接続が遮断された場合、 直ちに自動的に再接続し、ステートメントの送信を試みる(reconnect)。

注意:
再試行時には全セッションオブジェクトと設定(具体的にはテンポラリテーブル、オートコミットモード、ユーザー定義変数、 セッション変数、トランザクションロールバックなど)が失われているので、ステートメントによってはreconnectすることが危険なものもある。

reconnectしないようにmysqlクライアントを利用する場合には、--skip-reconnectオプションをつけてクライアントを立ち上げる。

@kitak
kitak / init.lua
Created November 27, 2016 23:11
hammerspoon config
local function keyCode(key, modifiers)
modifiers = modifiers or {}
return function()
hs.eventtap.event.newKeyEvent(modifiers, string.lower(key), true):post()
hs.timer.usleep(1000)
hs.eventtap.event.newKeyEvent(modifiers, string.lower(key), false):post()
end
end
local function keyCodeSet(keys)