cake, rails, spring boot, expressで、ほとんど同じアプリを作ってざっくり試してみる
Jmeterで負荷をかけることに
Jmeterインストール
$ brew install jmeter --with-plugins $ jmeter
1. Railsで最初にちょっと試してみる
Railsアプリをlocalhsot:3000で立てて...
rails 4.2.6 ruby 2.3.1 mysql 5.7.10
アプリ
こんなアプリ
/articles で記事+コメント一覧を表示する
コントローラ app/controllers/articles_controller.rb
class ArticlesController < ApplicationController def index @article = Article.includes(:comments).all end end
ビュー app/views/articles/index.erb
<h1>test</h1> <table> <tr> <th> タイトル </th> <th> 内容 </th> <th> 更新日 </th> </tr> <% @article.each do |article| %> <tr> <td> <%= article.name %> </td> <td> <%= article.content %> <% if article.comments.present? %> <br />コメント: <% article.comments.each do |comment| %> <br /><%= comment.content %> <% end %> <% end %> </td> <td> <%= article.updated_at %> </td> </tr> <% end%> </table>
テスト実施
このサイトの通り、パスだけアプリの/articlesに変えて
http://language-and-engineering.hatenablog.jp/entry/20081014/1223905380
左ペインの「テスト計画」を右クリックし,「追加」→「スレッドグループ」。
スレッド数: 50 Ramp-Up期間(秒): 10 (←スレッド立ち上げ期間のこと)
と入力。
左ペインの「スレッドグループ」を右クリックし,「追加」→「サンプラー」→「HTTPリクエスト」。
サーバ名またはIP: localhost パス: ./x.php
と入力。
左ペインの「スレッドグループ」を右クリックし,「追>加」→「リスナー」→「結果を表で表示」。
Ctrl+S し,保存。
ツールバーで「実行」→「開始」。
結果
平均25msってこと? webrickで、デバックで動かしてこれ
unicornでproductionだと、半分くらいになった。
2. 次はcake
cake php 3.2です
php 5.6 mysqlも5.6 細かいバージョンは忘れた
手抜きでmampで動かす DBはrailsと同じ感じだけど、カラム名等はcake標準になるように
アプリ
コントローラ /src/Controller/ArticlesController.php
<?php namespace App\Controller; class ArticlesController extends AppController { public function index(){ $articles = $this->Articles->find('all'); $this->set(compact('articles')); } }
ビュー /src/Template/Articles/index.ctp
<h1>test</h1> <table> <tr> <th> タイトル </th> <th> 内容 </th> <th> 更新日 </th> </tr> <? foreach($articles as $article){ ?> <tr> <td> <?= $article->name ?> </td> <td> <?= $article->content ?> <? if(count($article->comments) > 0){ ?> <br />コメント: <? foreach($comment as $article->comments){ ?> <br /><?= $comment->content ?> <? } ?> <? } ?> </td> <td> <?= $article->modified ?> </td> </tr> <? } ?> </table>
テスト実施
debugでない
平均 170ms なんでこんなに遅いのかな?
ここを参考に、OPcacheとついでにxdebugを止めてみる http://www.y-com.info/contents/?p=1165
がかえって遅くなる
dockerでサーバ立ててみたら更に遅い
3. spring boot(java)
spring boot 1.3.5 java 1.8.0_92
java8をいれるところから
brew cask install java
DBにつなげられない.....
途中
4. express(node.js)
途中
結果まとめ
途中
参考
spring boot
http://maplesystems.co.jp/blog/programming/18474.html https://www.jetbrains.com/help/idea/2016.1/creating-spring-boot-projects.html https://pgcolony.com/entry/117 http://confrage.jp/springmvc%E3%81%A7modelattribute%E3%82%A2%E3%83%8E%E3%83%86%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%99%E3%82%8B/ http://www.riem.nagoya-u.ac.jp/~ohta/etc/springboot-3.html
java8 http://www.task-notes.com/entry/20150406/1428289200 http://qiita.com/shuntaro_tamura/items/60b8c19f62edfd942c2e
jmetor
http://language-and-engineering.hatenablog.jp/entry/20081014/1223905380 めっちゃ古いけど
おまけ
ある時、 railsでこんなエラーがでるように
undefined method `tr' for nil:NilClass Did you mean? try Extracted source (around line #37): raise "Database URL cannot be empty" if url.blank? @uri = uri_parser.parse(url) @adapter = @uri.scheme.tr('-', '_') @adapter = "postgresql" if @adapter == "postgres" if @uri.opaque
database.ymlがうまく読み込まれていない
ヒント http://raysapida.github.io/more-debugging/
別なプロジェクトでDATABASE_URLという環境変数を設定してしまったせいだった
Rails使ってる環境でDATABASE_URLには気をつけろ