Archive for 5月, 2011

 

datastore low level っぽく pythonを使ってみる|google app engine

5月 10th, 2011

まずは、 .get_by_key_name()を調べてみました。 google\appengine\ext\db\__init__.py keys = [datastore.Key.from_path(cls.kind(), name, parent=parent) for name in key_names] if multiple: return get(keys, config=config) else: return get(keys[0], config=config) こうなっていたので Key.from_pathから kindと nameにkey_nameにしていたものを入れればOKと key = Key.from_path(‘myitem’, ‘my_test’) entity = Get(key) みたいな。 Putして Getしてみる。 Blob , datetime データはどうなる? entity = Entity(“bbtune”,name=”test2″) bdata = Blob(zlib.compress(‘tttttttttttttt’)) tdata = datetime.datetime.fromtimestamp(float(130000000)) entity.update({ ‘p': 100, ‘bdata': bdata, ‘tdata': tdata […]

Read full article | コメントは受け付けていません。

Billing Setting 課金設定をしてみる | google app engine

5月 9th, 2011

課金設定をしてみます。 左メニューの Billing Settings から Billing Status: Free Enable Billingボタンをクリック。 Customを選択すると以下のように入力欄が出て入れると計算して表示してくれます。 とりあえず、2.15ドルで。 下に行って、Countryを日本にして Review Weekly Contract : 一週間で最高 15.05$になりますという表示です。 問題なければ 最後に google checkです。 App Engine Budget – Maximum weekly budget for application ‘gr-aucru’, including applicable tax. 定期購入の詳細: 毎週、最大 USD 15.05 が請求されます。 開始時の残高 2011/05/09. という内容。 クレジットカードを入れて。Google CheckOUTを続けて 「ご注文が完了しました。」となります。 http://code.google.com/intl/ja/appengine/docs/billing.html app engineに戻って billing settingsを見ると Billing Status: Activating […]

Read full article | コメントは受け付けていません。

quota : cpuの使用量をチェック | google app engine

5月 9th, 2011

cpuは課金してみようと思います。 CPUの利用量がわかるらしいのでやってみます。 quota.pyとして置いてみました。 関数の前後で数字を取得して、差分をチェックしている例。 http://code.google.com/intl/ja/appengine/docs/quotas.html#Per-minute_Quotas import logging from google.appengine.api import quota start = quota.get_request_cpu_usage() do_something_expensive() end = quota.get_request_cpu_usage() logging.info(“do_something_expensive() cost %d megacycles.” % (start – end))

Read full article | コメントは受け付けていません。

awk match substrで後方参照

5月 9th, 2011

awk ‘BEGIN{all=0} {if(/int([0-9]*)/){ match($1,/[0-9]+/); all+= substr($1,RSTART,RLENGTH); }} END{print all}’ < 201004.cnt

Read full article | コメントは受け付けていません。

バックグラウンドで、コマンドを実行する | Cent os 5

5月 9th, 2011

&を付けるのだと駄目なんですね。 実行して、ctrl+zで止めてからbgで実行しました。 $ /tmp/aput.php 2>&1 > /tmp/aput.log Ctrl+Z で中断 [1] 終了しました /tmp/aput.php 2>&1 > /tmp/aput.log [2]+ Stopped /tmp/aput.php 2>&1 > /tmp/aput.log $ bg %2 [2]+ /tmp/aput.php 2>&1 > /tmp/aput.log & $ jobs [2]+ Running /tmp/aput.php 2>&1 > /tmp/aput.log & 実行中のものを止めたいときは、強制終了で。 $ jobs -pl [2]+ 12513 Running /tmp/aput.php 2>&1 > /tmp/aput.log & $ kill -9 12513 […]

Read full article | コメントは受け付けていません。

datastore putの速度 100件put | google app engine

5月 8th, 2011

datastore の putが遅いです。 でも複数のアイテムを同時に入れてもあまり変わらない?らしいので確認。 http://code.google.com/intl/ja/appengine/docs/python/datastore/overview.html にある通り500エンティティはput出来るようなのでついでに500も ( 0.3 sec は、ほとんどネットワークの問題です。) 1つのputに2.3秒かかります。 100個のputは4.3秒でした^-^。 500個のputは7.9秒でした^-^。 model詳細は適当に消したので気にしないでリストに100個入れてdb.put()するだけです。 model_list = [] for key in self.list: item = MyModel(key_name=self._generateKey( key )) item.en = datetime.datetime.fromtimestamp(float(self.list[key]['e'])) item.setData(self.list[key]['t'],self.list[key]['u'],self.list[key]['i'],self.list[key]['d']) item.pr = self.list[key]['p'] item.bi = self.list[key]['b'] model_list.append(item) db.put(model_list) 1件のときの結果 2.3605380058289 object(stdClass)#1 (2) { ["success"]=> int(1) ["error"]=> array(0) { } } 100件の時の結果 4.3123650550842 object(stdClass)#1 (2) { […]

Read full article | コメントは受け付けていません。

datastore putの速度 property name | google app engine

5月 8th, 2011

http://www.mail-archive.com/google-appengine@googlegroups.com/msg25095.html モデルのクラス名、プロパティ名は、短いほうがputの処理速度が速いそうです。 とりあえず、プロパティー名は、nameを付けることで、短く指定してみました。 price = db.IntegerProperty(name=’p’) CPU利用時間も変わるので、いちおモデル名も短めにしておきます。

Read full article | コメントは受け付けていません。

google app engine の速度

5月 8th, 2011

簡単な速度を。 さくらのVPSからabの結果です。 結果 300ms-500ms というところでした。 悪くはないですね。 あたり前ですが、さくらのネットワーク内のコンテンツとは比較にならないので。。。 やっぱり自前のAPIはさくら内に持つかフロントをすべてapp engineへ移行するかの2択のようです。 数段階のアクセスは無理なので。現状は大規模データだけ任せて細かい所は現状と同じく memcached +mysql , tokyotyrantで行くしかなさそうです。 1. 通常テキストページ # ab -n 100 -c 20 http://gr—–.appspot.com/ Server Software: Google Server Hostname: gr—–.appspot.com Server Port: 80 Document Path: / Document Length: 398 bytes Concurrency Level: 20 Time taken for tests: 1.746154 seconds Complete requests: 100 Failed requests: 0 Write […]

Read full article | コメントは受け付けていません。

UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 2-8: ordinal not in range(128) | Google App Engine

5月 7th, 2011

UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 2-8: ordinal not in range(128) なんぞこれ。 import sys print sys.getdefaultencoding() ascii だそうで、これが駄目なようで。。。 通常のpythonは、 sitecustomize.py に import sys sys.setdefaultencoding(‘utf-8′) を追加すればいいそうです。 app engineでは、それを各場所が無いので。直接読み込まれるファイルに書かないといけないそうです。 app.yamlに設定してあるファイルに書く必要があるそうでデフォルト main.pyでしょうか。 main.pyの先頭に import sys if ‘ascii’==sys.getdefaultencoding(): stdin = sys.stdin stdout = sys.stdout reload(sys) sys.setdefaultencoding(‘utf-8′) sys.stdin = stdin sys.stdout = stdout と書いてみました。 reload(sys)が無いとだめで。stdin stdoutのデータ保管も初回は無いとだめな感じで。 ローカルの場合は、1ファイルだけ更新とかあるので、何度も読み込まれないけど、本番環境は、更新時だけかな? とりあえず。

Read full article | コメントは受け付けていません。

for の使い方 python

5月 7th, 2011

Cやphpのようなforを使いたいとき。 あるシーケンスにわたってインデクスで反復を行うには、 range() と len() を次のように組み合わせます: >>> a = ['Mary', 'had', 'a', 'little', 'lamb'] >>> for i in range(len(a)): … print i, a[i] … 0 Mary 1 had 2 a 3 little 4 lamb

Read full article | コメントは受け付けていません。