Siege


20160126siege

Siege は、HTTP のロードテストやベンチマークのユーティリティです。
ちなみに、Siege とは、城などを包囲して攻撃することです。

インストール

$ brew install siege
...
/usr/local/Cellar/siege/3.1.3: 18 files, 249.6K

使い方

$ siege http://localhost/ -c10 -t10s

結果の例

Transactions:		          92 hits
Availability:		      100.00 %
Elapsed time:		        9.18 secs
Data transferred:	        0.02 MB
Response time:		        0.40 secs
Transaction rate:	       10.02 trans/sec
Throughput:		        0.00 MB/sec
Concurrency:		        4.05
Successful transactions:          92
Failed transactions:	           0
Longest transaction:	        0.75
Shortest transaction:	        0.09

参考
WEBサイト負荷テストツール7選


MongoDB


20160124mongodb

MongoDB は、NoSQL 型のデータベースです。
BSON と呼ばれる JSONのバイナリ版でデータを保存します。

インストール

$ brew install mongodb

起動

$ mongod --config /usr/local/etc/mongod.conf &

バージョン確認

$ mongo -version
MongoDB shell version: 3.0.7

CRUD操作
下記にサンプルが掲載されています。
Getting Started with MongoDB (MongoDB Shell Edition)

対話型シェルを開始する

$ mongo

データの Create

use test

db.restaurants.insert(
   {
      "address" : {
         "street" : "2 Avenue",
         "zipcode" : "10075",
         "building" : "1480",
         "coord" : [ -73.9557413, 40.7720266 ],
      },
      "borough" : "Manhattan",
      "cuisine" : "Italian",
      "grades" : [
         {
            "date" : ISODate("2014-10-01T00:00:00Z"),
            "grade" : "A",
            "score" : 11
         },
         {
            "date" : ISODate("2014-01-16T00:00:00Z"),
            "grade" : "B",
            "score" : 17
         }
      ],
      "name" : "Vella",
      "restaurant_id" : "41704620"
   }
)

WriteResult({ "nInserted" : 1 })

データの Read

db.restaurants.find()

{ "_id" : ObjectId("56af84dea36250ac8cfad145"), "address" : { "street" : "2 Avenue", "zipcode" : "10075", "building" : "1480", "coord" : [ -73.9557413, 40.7720266 ] }, "borough" : "Manhattan", "cuisine" : "Italian", "grades" : [ { "date" : ISODate("2014-10-01T00:00:00Z"), "grade" : "A", "score" : 11 }, { "date" : ISODate("2014-01-16T00:00:00Z"), "grade" : "B", "score" : 17 } ], "name" : "Vella", "restaurant_id" : "41704620" }

以下、省略


OctoPrint for MAC


20160114_ocot_print

OctoPrint は、3Dプリンタを制御するWEBアプリです。
Linux版、Windows版、MAC版があります。

1. 前準備
(1) Xcode のインストール
ダウンロード

(2) homebrew のインストール

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

(3) python 2.7 のインストール

$ brew install python

(4) virtualenv のインストール
virtualenv Python を仮想環境で動作させるツールです。

$ pip install virtualenv

2. OctoPrint のインストール
(1) ソースをダウンロードする

$ cd ~
$ git clone https://github.com/foosel/OctoPrint.git

(2) OctoPrint ディレクトリに移動する

$ cd OctoPrint

(3) venv ディレクトリに Python の仮想環境を作成する

$ virtualenv venv

(4) 仮想環境を開始する。
以降、仮想環境を示す vent が表示されます。

$ source venv/bin/activate

(5) pyobjc をインストールする。
pyobjc は、Python を MAC の環境 (Objective-C) で動作させるツールです。
Setup on Mac では、pyobjc-core となっていますが、pyobjc が正しいです。

(venv) $ pip install -U pyobjc
(メッセージがいっぱい表示されるので、省略)
Successfully installed pyobjc-3.0.4 ...

(6) OctoPrint をインストールする。

(venv) $ python setup.py install
(メッセージがいっぱい表示されるので、省略)
Finished processing dependencies for OctoPrint==1.2.8

(7) 仮想環境を終了する

$ deactivate

3. OctoPrint の初期設定
(1) OctoPrint を起動する

$ cd ~
$ OctoPrint/venv/bin/octoprint
octoprint.server - INFO - Starting OctoPrint 1.2.8 (master branch)
 ...
octoprint.server - INFO - Listening on http://0.0.0.0:5000

(2) WEBブラウザでアクセスする
http://localhost:5000/

(3) Configure Access Control が表示されるので、Username と Password を設定します。
20160117_octo_print_configure_access_control

(4) 右上の「Login」に、設定した Username と Password を入力します。
20160117_octo_print_login

備考1
インストールされた Python ライブラリの一覧

$ source venv/bin/activate
(venv) $ pip freeze
altgraph==0.12
argh==0.26.1
Babel==2.2.0
backports.ssl-match-hostname==3.5.0.1
blinker==1.4
certifi==2015.11.20.1
Flask==0.10.1
Flask-Assets==0.10
Flask-Babel==0.9
Flask-Login==0.2.2
Flask-Principal==0.3.5
itsdangerous==0.24
Jinja2==2.8
macholib==1.7
MarkupSafe==0.23
modulegraph==0.12.1
netaddr==0.7.17
netifaces==0.10.0
OctoPrint==1.2.8
pathtools==0.1.2
pkginfo==1.2.1
psutil==3.2.1
py2app==0.9
pyasn1==0.1.9
pylru==1.0.9
pyobjc==3.0.4
pyobjc-core==3.0.4
pyobjc-framework-Accounts==3.0.4
pyobjc-framework-AddressBook==3.0.4
pyobjc-framework-AppleScriptKit==3.0.4
pyobjc-framework-AppleScriptObjC==3.0.4
pyobjc-framework-Automator==3.0.4
pyobjc-framework-CalendarStore==3.0.4
pyobjc-framework-CFNetwork==3.0.4
pyobjc-framework-Cocoa==3.0.4
pyobjc-framework-Collaboration==3.0.4
pyobjc-framework-CoreData==3.0.4
pyobjc-framework-CoreLocation==3.0.4
pyobjc-framework-CoreText==3.0.4
pyobjc-framework-CoreWLAN==3.0.4
pyobjc-framework-DictionaryServices==3.0.4
pyobjc-framework-DiskArbitration==3.0.4
pyobjc-framework-EventKit==3.0.4
pyobjc-framework-ExceptionHandling==3.0.4
pyobjc-framework-FSEvents==3.0.4
pyobjc-framework-InputMethodKit==3.0.4
pyobjc-framework-InstallerPlugins==3.0.4
pyobjc-framework-InstantMessage==3.0.4
pyobjc-framework-LatentSemanticMapping==3.0.4
pyobjc-framework-LaunchServices==3.0.4
pyobjc-framework-PreferencePanes==3.0.4
pyobjc-framework-PubSub==3.0.4
pyobjc-framework-QTKit==3.0.4
pyobjc-framework-Quartz==3.0.4
pyobjc-framework-ScreenSaver==3.0.4
pyobjc-framework-ScriptingBridge==3.0.4
pyobjc-framework-SearchKit==3.0.4
pyobjc-framework-ServiceManagement==3.0.4
pyobjc-framework-Social==3.0.4
pyobjc-framework-StoreKit==3.0.4
pyobjc-framework-SyncServices==3.0.4
pyobjc-framework-SystemConfiguration==3.0.4
pyobjc-framework-WebKit==3.0.4
pyserial==2.7
pytz==2015.7
PyYAML==3.10
requests==2.7.0
rsa==3.2
sarge==0.1.4
semantic-version==2.4.2
sockjs-tornado==1.0.1
speaklater==1.3
tornado==4.0.1
watchdog==0.8.3
webassets==0.11.1
Werkzeug==0.8.3
wheel==0.26.0

備考2
OctoPrint をインストールしたとき、下記の warning が出ますが、無視していいようです。

warning: no previously-included files matching '*' found under directory 'docs/_build'
warning: manifest_maker: MANIFEST.in, line 18: 'recursive-include' expects <dir> <pattern1> <pattern2> ...
warning: no files found matching 'README'
warning: no files found matching '*.h' under directory 'src'
warning: unknown warning option
src/watchdog_fsevents.c:136:63: warning: unused parameter 'stream_ref'
src/watchdog_fsevents.c:141:63: warning: unused parameter 'event_ids'
src/watchdog_fsevents.c:334:30: warning: unused parameter 'self'
src/watchdog_fsevents.c:417:32: warning: unused parameter 'self'
src/watchdog_fsevents.c:466:33: warning: unused parameter 'self'
src/watchdog_fsevents.c:491:25: warning: unused parameter 'self'
src/watchdog_fsevents.c:531:10: warning: missing field 'ml_meth' initializer
warning: no previously-included files matching '*.pyc' found under directory 'tests'
warning: no previously-included files matching '*.pyo' found under directory 'tests'
warning: no previously-included files matching '*.pyc' found under directory 'example'
warning: no previously-included files matching '*.pyc' found under directory 'tests'
warning: no previously-included files matching '*.pyo' found under directory 'tests'
warning: no previously-included files matching '*.pyc' found under directory 'docs'
warning: no previously-included files matching '*.pyo' found under directory 'docs'
warning: no previously-included files matching '*.pyc' found under directory 'examples'
warning: no previously-included files matching '*.pyo' found under directory 'examples'
warning: no files found matching '*' under directory 'werkzeug/debug/templates'
warning: no files found matching '*' under directory 'tests'
warning: no files found matching 'run_tests.py'
warning: no previously-included files matching 'out.css' found under directory 'examples'
warning: no previously-included files matching 'out.js' found under directory 'examples'
warning: no previously-included files matching '*.pyc' found anywhere in distribution
warning: no previously-included files matching '.gitignore' found anywhere in distribution
warning: no previously-included files matching '*.orig' found anywhere in distribution
warning: no previously-included files matching 'webassets-cache/*' found anywhere in distribution
warning: no previously-included files matching '.sass-cache/*' found anywhere in distribution
warning: no files found matching 'run-tests.py'
warning: no files found matching '*' under directory 'custom_fixers'
warning: no files found matching '*' under directory 'jinja2/testsuite/res'
warning: no previously-included files matching '*' found under directory 'docs/_build'
warning: no previously-included files matching '*.pyc' found under directory 'jinja2'
warning: no previously-included files matching '*.pyo' found under directory 'jinja2'
warning: no previously-included files matching '*' found under directory 'docs/_build'

参考
Setup on Mac – OctoPrint


brew で node をインストールする


Node.js は Unix系で動作するサーバーサイドの JavaScript 環境です。

インストールする

$ brew install node
==> Downloading https://homebrew.bintray.com/bottles/node-0.12.0.mavericks.bottl
Already downloaded: /Library/Caches/Homebrew/node-0.12.0.mavericks.bottle.1.tar.gz
==> Pouring node-0.12.0.mavericks.bottle.1.tar.gz
==> Caveats
If you update npm itself, do NOT use the npm update command.
The upstream-recommended way to update npm is:
  npm install -g npm@latest

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
 /usr/local/Cellar/node/0.12.0: 2196 files, 25M

npm をアップデートする

$ npm install -g npm@latest
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
npm@2.6.1 /usr/local/lib/node_modules/npm

パスとバージョンを確認する

$ which node
/usr/local/bin/node
$ node -v
v0.12.0

動作確認
サンプルコードを書く
example.js

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

起動する

$ node example.js
Server running at http://127.0.0.1:1337/

WEBブラウザからアクセスする。
「Hello World」が表示されれば、OK

備考
いったん node.js のサイト にある MAC用のパッケージをインストールしたから、
brew を試したら、いろいろエラーが出た。

$ brew install node
==> Downloading https://homebrew.bintray.com/bottles/node-0.12.0.mavericks.bottl
######################################################################## 100.0%
==> Pouring node-0.12.0.mavericks.bottle.1.tar.gz
==> Caveats
If you update npm itself, do NOT use the npm update command.
The upstream-recommended way to update npm is:
  npm install -g npm@latest

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/node
Target /usr/local/bin/node
already exists. You may want to remove it:
  rm '/usr/local/bin/node'

To force the link and overwrite all conflicting files:
  brew link --overwrite node

To list all files that would be deleted:
  brew link --overwrite --dry-run node

Possible conflicting files are:
/usr/local/bin/node
/usr/local/share/man/man1/node.1
/usr/local/share/systemtap/tapset/node.stp
/usr/local/lib/dtrace/node.d
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall node`
==> Summary
 /usr/local/Cellar/node/0.12.0: 2196 files, 25M

brew で git をインストールする


Git は、分散型バージョン管理システムです。

インストールしようとすると、下記のエラーが出る

$ brew install git
/usr/local/share/git-core is not writable.
Permission denied - /usr/local/lib/perl5/site_perl/5.16.2

/usr/local 配下のパーミッションを変更する

$ sudo chown -R $USER:admin /usr/local

再度、インストールすると、うまくいく。

$ brew uninstall git
==> Downloading https://homebrew.bintray.com/bottles/git-2.3.1.mavericks.bottle.
Already downloaded: /Library/Caches/Homebrew/git-2.3.1.mavericks.bottle.tar.gz
==> Pouring git-2.3.1.mavericks.bottle.tar.gz
==> Caveats
The OS X keychain credential helper has been installed to:
  /usr/local/bin/git-credential-osxkeychain

The "contrib" directory has been installed to:
  /usr/local/share/git-core/contrib

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completion has been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
  /usr/local/Cellar/git/2.3.1: 1359 files, 31M

パスとバージョンを確認する

$ which git
/usr/local/bin/git
$ git --version
git version 2.3.1

備考
いったん、git のサイト にある MAC用のパッケージをインストールしてから、
brew を試したら、いろいろエラーが出た。

==> Downloading https://homebrew.bintray.com/bottles/git-2.3.1.mavericks.bottle.
######################################################################## 100.0%
==> Pouring git-2.3.1.mavericks.bottle.tar.gz
==> Caveats
The OS X keychain credential helper has been installed to:
  /usr/local/bin/git-credential-osxkeychain

The "contrib" directory has been installed to:
  /usr/local/share/git-core/contrib

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completion has been installed to:
  /usr/local/share/zsh/site-functions
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/git-core/contrib
/usr/local/share/git-core is not writable.

You can try again using:
  brew link git
==> Summary
 /usr/local/Cellar/git/2.3.1: 1359 files, 31M