Apache Use LogLevel debug to get a backtrace.

Apache

Apache Use LogLevel debug to get a backtrace.

Apacheのログのレベルを変更すると、より詳細にログを取得することができます。

httpd.confに

 LogLevel debug

と書いておくとログレベルがdebugになります。

Apache ab(ApacheBench)で負荷テストする

Apache

Apacheに付属するApacheBenchというプログラムで単一のURLに対して負荷テストを行うことができます。
※複数のURLに対して複雑なテストを行いたい場合は、Apache JMeter等がつかえます。

「-n」でリクエスト数を、「-c」で同時接続数を指定します。

 $ ab -n 100 -c 100 http://localhost/
 This is ApacheBench, Version 2.3 <$Revision: 655654 $>
 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
 Licensed to The Apache Software Foundation, http://www.apache.org/
 
 Benchmarking example.com (be patient).....done
 
 
 Server Software:        Apache
 Server Hostname:        localhost
 Server Port:            80
 
 Document Path:          /
 Document Length:        13888 bytes
 
 Concurrency Level:      100
 Time taken for tests:   6.815 seconds
 Complete requests:      100
 Failed requests:        0
 Write errors:           0
 Total transferred:      1432400 bytes
 HTML transferred:       1388800 bytes
 Requests per second:    14.67  (mean)
 Time per request:       6815.211 [ms] (mean)
 Time per request:       68.152 [ms] (mean, across all concurrent requests)
 Transfer rate:          205.25 [Kbytes/sec] received
 
 Connection Times (ms)
               min  mean[+/-sd] median   max
 Connect:      119  163  25.8    163     209
 Processing:    97 3593 1900.9   3737    6696
 Waiting:       78 3569 1903.5   3691    6678
 Total:        217 3756 1914.7   3912    6815
 
 Percentage of the requests served within a certain time (ms)
   50%   3912
   66%   4911
   75%   5451
   80%   5824
   90%   6346
   95%   6646
   98%   6751
   99%   6815
  100%   6815 (longest request)
 

BASIC認証が必要な場合は「-A」で、ユーザー名:パスワードを指定します。

  ab -n 100 -c 100 -A ユーザー名:パスワード "http://localhost/param1=value1&param2=value2"

GET

  • クエリーストリングを含むURLを「”」でくくります
  •  ab -n 100 -c 100 -A ユーザー名:パスワード http://localhost/?
    

    POST

    • ポストするデータをテキストファイルに記述し、「-p」でそのファイル名を、「-T」でポストするデータのContent-typeを指定します。
     ab -n 10 -c 10 -p post_data.txt -T "application/x-www-form-urlencoded" http://localhost/
    

    ポストデータファイルは以下のように記述し、URLエンコードしたものを使います。

     param1=value1&param2=value2+value3
    

    URLエンコードされたファイルを作成する例です。

     php -r 'echo urlencode("param1=value1&param2=value2+value3");' > post_data.txt
    
    • ファイルをポストする場合は下記のようになります
     ab -n 100 -c 10 -p post_file -T "multipart/form-data"
    

Android 改行について

Android

改行が無視される!?

WEBで入力された文字列を渡しAndroidで表示させる、という処理で、
Androidで表示しようとしたら改行が無視された(半角スペースが入っている?)。
以下のように、複数行OKの設定をしないとダメなようですね。

 txtView.setRawInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);

とりあえず、これで出来たので今回はこれで調査終わり。
また他にも出てきたら追記していきます。

Android 既存のファイルシステムからプロジェクトを作る

Android

Android 既存のファイルシステムからプロジェクトを作る

  1. EclipseのPackage Explorerの何もないところを右クリックして、Importをクリックします。
  2. Android → Existing Android Code Into Workspace をクリック

General→File Systemだと 「Source is in the hierarchy of the destination.」となってエラーでインポートできません。

  1. Root Directoryと書いてあるところの右のBrowserをクリックし、インポートしたいディレクトリを選択します。
  2. Invalid project description.となってしまう場合は、すでにEclipseのWork spaceに同じ名前のプロジェクトがあるか、そもそも同じWork spaceからインポートしようとしているというケースです。work spaceとは違う場所からimportしましょう。

Android 日本語でフォーマットされた日付を返すサンプルコード

Android
Java

Android 日本語でフォーマットされた日付を返すサンプルコード

Calendarを使って、日本語でフォーマットされた日付(2013年11月21日 11時30分)を返します。
何度か使いそうなので、書いておきます。

 //src内
 public static String getJapaneseDate(Calendar calendar, Context context){
 	
 	int year = calendar.get(Calendar.YEAR);
 	int month = calendar.get(Calendar.MONTH) + 1;
 	int date = calendar.get(Calendar.DATE);
 	int hour = calendar.get(Calendar.HOUR_OF_DAY);
 	int minute = calendar.get(Calendar.MINUTE);
 		
 	String japanese_date = Integer.toString(year) + context.getString(R.string.year) 
 			+ Integer.toString(month) + context.getString(R.string.month) 
 			+ Integer.toString(date) + context.getString(R.string.date) 
 			+ Integer.toString(hour) + context.getString(R.string.hour) 
 			+ Integer.toString(minute) + context.getString(R.string.minute); 
  		
 	return japanese_date;
 		
 }
 //strings.xml内
 <string name="year">年</string>
 <string name="month">月</string>
 <string name="date">日</string>
 <string name="hour">時</string>
 <string name="minute">分</string>