Archive for the ‘Python’ Category

 

@staticmethod static function | Python

9月 26th, 2011

@staticmethod
def generateKey( auction_id, user_id, price, updated_at ):
key = auction_id + ‘__’ + user_id

@staticmethodをつけるとpublic staticになる。
暗黙の第一引数 selfを取らない。

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

GQLで検索

6月 29th, 2011

q = db.GqlQuery(”SELECT * FROM items WHERE endtime > DATETIME(’2010-06-01 00:00:00′) order by endtime,bpoint desc LIMIT 10″)
if q.count() > 0 :
for i in q:
print(i.key().name())

・不等式を endtimeで行うとき [...]

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

GQLの制限

6月 29th, 2011

http://code.google.com/intl/ja/appengine/docs/python/datastore/queriesandindexes.html#Restrictions_on_Queries
・不等式フィルタが使用できるのは 1 つのプロパティに限られる
・他の並び替え順序より先に、不等式フィルタのプロパティを並び替える必要がある
さてどうしようか。
カラムを一つ増やせば対応できるけど無理だな。
日時を日だけにしたらいけるけど時間が必要かどうか・・・
月別統計、日別統計のデータを作りたかったらそれぞれのカラムがあったほうが使える・・・

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

timeout 500 error code 104 | google app engine

5月 21st, 2011

30秒エラーが頻発しています。。。
datastoreにputしているときに起きているようなのですが
原因はわかりません、datastoreと関係なく出ていることもあるようです。
instanceが初期化されたときにこういうエラーが起きる可能性が高いような感じですがわかりません。
今までとの違いは、datastoreのデータが増えてきたことくらいです。
とは言ってもまだ 3GB程度です。
これでputが遅くなったりする理由とも考えられません。
謎。
500 30143ms 31cpu_ms 8api_cpu_ms

A serious problem was encountered with the process that handled this request, causing it to exit. This is likely to cause a new process to be used for the next request to your application. If you see this message frequently, you may be throwing exceptions during the initialization of your application. [...]

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

install Lucene PHP for centos 64bit

5月 11th, 2011

# yum search lucene

Loaded plugins: fastestmirror
Determining fastest mirrors
* addons: ftp.nara.wide.ad.jp
* base: ftp.nara.wide.ad.jp
* epel: ftp.kddilabs.jp
* extras: ftp.nara.wide.ad.jp
* updates: ftp.nara.wide.ad.jp
addons [...]

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

db.Model+db.put()と Entity+datastore.Put()の速度比較 python | google app engine

5月 10th, 2011

とりあえず、書いてみたのですが予想通り。
datastore.Putは db.putの中で呼ばれてるだけなので、やってることは一緒ということで差はありませんでした。
Model , 各 propertyも何か邪魔になるようなこともしていないようで。
50件put
db.Model継承 db.put

319ms 2210cpu_ms 2000api_cpu_ms | cost -254 megacycles.
273ms 2210cpu_ms 2000api_cpu_ms | cost -245 megacycles.
250ms 2210cpu_ms 2000api_cpu_ms | cost -235 megacycles.
334ms 2233cpu_ms 2000api_cpu_ms | cost -271 megacycles.
665ms 2210cpu_ms 2000api_cpu_ms | cost -267 megacycles.

直接 entity作って、datastore.Put。low level api

470ms 2233cpu_ms 2000api_cpu_ms | cost -249 megacycles.
370ms 2186cpu_ms 2000api_cpu_ms | cost -233 megacycles.
252ms 2233cpu_ms 2000api_cpu_ms | cost [...]

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

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 [...]

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 | コメントは受け付けていません。

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']))
[...]

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 | コメントは受け付けていません。