query: tag:yak

Merb/DataMapperをしばらく使っていたのですが、
少なくともバージョン0.9.10, 0.9.11では、
associationの実装にバグがあり、
レコード数が多いテーブルがあると、aggregation系の処理に時間がかかるという問題がある事が分かりました。

例えば、Post.has n, :comments な関係がある時に、
以下のようなコードを実行すると、このようになります。

ruby>>
?> Post.first.comments.count #=> 188
~ (0.000865) SELECT "id" FROM "posts" ORDER BY "id" LIMIT 1
~ (0.000094) SELECT "id", "post_id" FROM "comments" WHERE ("post_id" IN (1)) ORDER BY "id"
~ (0.000063) SELECT COUNT(*) FROM "comments" WHERE ("post_id" = 1)
<<--

2つ目のSQLは不要なのですが、発行されてしまいます。
例えばCommentのレコード数が多かった場合、Commentオブジェクトを大量に生成しようとしてしまうため、致命的な遅さになってしまいます。

目下この問題の解決策を探しているところですが、
Edge-DMのspec/仕様でerrorが出ている状態なので、なかなか手が付けられない感じです。
とりあえず、dm-coreのassociations/relationship.rbの中の、

ruby>>
# @api private
def get_children(parent, options = {}, finder = :all, *args)
parent_value = parent_key.get(parent)
bind_values = [ parent_value ]

    with_repository(child_model) do |r|
      parent_identity_map = parent.repository.identity_map(parent_model)

      query_values = parent_identity_map.keys
      bind_values = query_values unless query_values.empty?
      query = child_key.zip(bind_values.transpose).to_hash
      collection = child_model.send(finder, *(args.dup << @query.merge(optio

ns).merge(query)))

      return collection unless collection.kind_of?(Collection) && collection.any?

<<--

の最後の collection.any? で件のSQLが実行されているところまでは分かりました。
DataMapper::CollectionはextlibのLazyArrayを継承しているクラスなのですが、どうもそのへんの仕様が変わったのに追従できてないのかな。
モジュールを過度に分散しすぎるのも、整合性を保つのが大変になるという問題がありますね。
注意深く完全なSpecを書く事を心がけていれば防げる問題かもしれないですが。

posted by genki genki on Wed 8 Apr 2009 at 04:52 with 0 comments

最近の釣果ならぬYak Shaving状況:

  • watch.s21g.com が重たくて固まる
  • CouchDB-adapterを疑ってmysqlに戻す
  • まだ遅いのでdm-aggregatesを調査
  • dm-core が原因っぽいのでdm-coreのソースを見る
  • dm-core のスペックが通らない
  • postgresが必要なのでインストール
  • Mac用インストーラではdo_postgresがmakeできない
  • postgresをソースからインストール <- いまここ

ということで、MacOSにPostgresを入れるためにユーザを作成する手順のメモ。

pre>>

dscl . -create /Users/postgres

dscl . -create /Users/postgres UserShell /bin/bash

dscl . -create /Users/postgres RealName "Postgres"

dscl . -create /Users/postgres UniqueID 451

dscl . -create /Users/postgres PrimaryGroupID 451

dscl . -create /Users/postgres NFSHomeDirectory /usr/local/pgsql

<<--

UID/GIDの根拠は自信が無い。UIDは500未満にしておくとログイン画面にでないようになるそうだ。

Alas, life is full of yakshaving!

See Also

posted by genki genki on Tue 7 Apr 2009 at 23:36 with 0 comments

I am using merb with passenger on our production server.
The passenger is going well in most of cases.
But if dependent gems have been updated, it becomes acting up when it got restarted.
After I encountered such situations several times, I decided to begin investigation about the issue.

Detail of the issue is as follows.

  • My merb app becomes causing errors after restarting of passenger by "touch tmp/restart.txt" if dependency gems were updated and they have no compatibility.
  • Even if the gems were compatible, my merb app kept using old gems until apache is reloaded.
  • pids were changing successfully while restarting.
  • /etc/init.d/apache reload can refresh everything as expected.
  • "touch tmp/restart.txt" can't.

I wonder there is the master of master processes which keeps LOAD_PATH and it is refusing to use new gems.
I am thinking I should investigate the Rack.

Update

Finally, the issue was solved!

The solution is found here

posted by takiuchi takiuchi on Sat 17 Jan 2009 at 22:41 with 0 comments

今年は作業ログの前段階の調べてる事についても、yakタグをつけて書いておこうと思います。解決したらshavedタグでもつけようかな。

さて、掲題の件ですが、ruby-localeを使って、

ruby>>
Locale::Tag.parse("ja").country #=> "JP"
<<--

が得られたら良いな、という事です。
現状では無情にもnilが返ってきます。

ブラウザが送ってくるHTTP_ACCEPT_LANGUAGEが、お行儀よく
ja_JPやja-JPを指定してくれると良いのですが、
そうとは限らないので、"ja"から"JP"を推測するような必要性が出てきます。

もちろん、"en"の場合は"US"だったり"UK"だったり"AU"だったりするわけで、
mappingは単射ではないのですが、そういう言語を使ってる場合は、
最初から"en_US"などと、ちゃんと国コードまで含めたものを送ってくる場合が多いので、そんなに困らなかったりします。

[math]
f_{lc}:\mbox{language}\mapsto\mbox{country}
[/math]

あるいは

[math]
f_{cl}:\mbox{country}\mapsto\mbox{language}
[/math]

を取得する方法無いかなー。

とりあえず、変換テーブルを作ってみた。

ruby>>
{"nn"=>["NO"], "uk"=>["UA"], "it"=>["SM", "GI", "CH", "LY", "IT"], "zh_TW"=>["TT", "VN", "HK"], "no"=>["NO"], "st"=>["ZA"], "tk"=>["TM"], "bn"=>["IN"], "mn"=>["MN"], "ja"=>["JP"], "fr"=>["TT", "CD", "GG", "RW", "CG", "LU", "FR", "CH", "CI", "JE", "SC", "VN", "BE", "MU", "DJ", "BI", "CA"], "hi"=>["TT", "AE", "IN"], "de"=>["AT", "LU", "CH", "LI", "DE", "BE", "RO"], "ne"=>["NP"], "jw"=>["ID"], "ta"=>["IN", "SG"], "tl"=>["PH"], "pt_PT"=>["PT", "GI"], "hu"=>["SK", "HU", "RO"], "sk"=>["SK"], "fi"=>["FI"], "sv"=>["SE", "FI"], "iw"=>["IL"], "az"=>["AZ"], "zh"=>["TW"], "ru"=>["KG", "KZ", "RU", "AZ", "LV", "UA", "TM", "AM", "UZ"], "ky"=>["KG"], "es"=>["EC", "HN", "CU", "PR", "TT", "PA", "VE", "DO", "BO", "GI", "PE", "PY", "NI", "CL", "SV", "CO", "UY", "BZ", "CR", "ES", "GT", "AR", "MX"], "ko"=>["KR"], "pt_BR"=>["BR"], "sw"=>["RW", "KE"], "ga"=>["IE"], "id"=>["ID"], "eu"=>["ES"], "gl"=>["ES"], "xh"=>["ZA"], "uz"=>["TM", "UZ"], "mr"=>["IN"], "fa"=>["AE"], "zu"=>["LS", "ZA"], "af"=>["NA", "ZA"], "pl"=>["PL"], "hy"=>["AM"], "pa"=>["PK"], "te"=>["IN"], "ar"=>["AE", "LY", "SA", "DJ"], "ms"=>["MY", "SG"], "el"=>["GR"], "ro"=>["RO"], "mt"=>["MT"], "ur"=>["AE", "PK"], "da"=>["DK", "GL"], "ca"=>["ES"], "tr"=>["TR"], "zh_CN"=>["SG"], "nl"=>["NL", "BE", "ID"], "vi"=>["VN"], "lt"=>["LT", "LV"], "th"=>["TH"], "fo"=>["DK"], "en"=>["AS", "IE", "NP", "MY", "UK", "FM", "VC", "PR", "TT", "AU", "PA", "NA", "GG", "LS", "RW", "VG", "AE", "GI", "VI", "AG", "TH", "CH", "NF", "JE", "AI", "GL", "PH", "CK", "GM", "LY", "IN", "NZ", "NI", "SC", "PK", "VN", "MS", "TO", "MT", "BE", "PN", "MU", "UG", "SG", "ZA", "BZ", "SH", "MW", "FJ", "CR", "HK", "JM", "KE", "CA", "ID"], "lv"=>["LV"]}
<<--

posted by genki genki on Sat 3 Jan 2009 at 17:03 with 0 comments