とんたんの技術メモ

注)ただのメモです。

MacでApacheBenchを使う

macにはデフォルトでApacheBenchが入ってるので以下を実行してみる

ab -n 1000 -c 1000 https://kireininare.co/hello/
# -c 同時に1000人が
# -n 1リクエストを発行する
例えば、1000人が10リクエストを発行する場合は、n = 10000

こんなエラーが出る場合、Macのファイル数の上限を上げる必要がある

socket: Too many open files (24)

設定ファイルを作成する

# 現状の確認(open filesとmax user processesの上限を確認する)
ulimit -a
sudo vi /Library/LaunchDaemons/limit.maxfiles.plist
----
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>limit.maxfiles</string>
    <key>ProgramArguments</key>
    <array>
      <string>launchctl</string>
      <string>limit</string>
      <string>maxfiles</string>
      <string>524288</string>
      <string>524288</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>ServiceIPC</key>
    <false/>
  </dict>
</plist>
----

sudo vi /Library/LaunchDaemons/limit.maxproc.plist
----
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
    <dict>
      <key>Label</key>
        <string>limit.maxproc</string>
      <key>ProgramArguments</key>
        <array>
          <string>launchctl</string>
          <string>limit</string>
          <string>maxproc</string>
          <string>2048</string>
          <string>2048</string>
        </array>
      <key>RunAtLoad</key>
        <true />
      <key>ServiceIPC</key>
        <false />
    </dict>
  </plist>
----

# 権限を変更
sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
sudo launchctl load -w /Library/LaunchDaemons/limit.maxproc.plist