1 / 16

(LT) PHP のガベコレについて ( 小ネタ ) ~ PHP と refcount と copy on write ~

(LT) PHP のガベコレについて ( 小ネタ ) ~ PHP と refcount と copy on write ~. 2010 年 5 月 16 日 ( 日 ) yoya. GCの種類. 参照カウント法 軽い。実装も軽いし動作も軽い、とくかく軽い php-5.2.9/Zend/zend.h refcount. GC処理. zend_assign_to_variable ( 変数への代入処理 ) 古いデータの refcount を減らして 0 だったら廃棄 (dtor) 分かりやすい! 素晴らしい!!!. デメリット.

mason
Download Presentation

(LT) PHP のガベコレについて ( 小ネタ ) ~ PHP と refcount と copy on write ~

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. (LT) PHP のガベコレについて (小ネタ)~PHP と refcount と copy on write~ 2010年5月16日(日)yoya

  2. GCの種類 • 参照カウント法 • 軽い。実装も軽いし動作も軽い、とくかく軽い php-5.2.9/Zend/zend.h refcount

  3. GC処理 • zend_assign_to_variable(変数への代入処理) 古いデータの refcount を減らして 0 だったら廃棄 (dtor) 分かりやすい! 素晴らしい!!!

  4. デメリット • 「カウンタに多くのビットが必要」 (GC本p47) • php-5.2.9/Zend/zend.h • php-4.4.9/Zend/zend.h

  5. PHP4での問題 • ushort :0 ~65535 • これだけあれば十分? 問題は、copy on write でも refcount を使っている事

  6. debug_zval_dump • zval 構造体(全ての型の変数を統合して扱う型)を dump するメソッド ↓ 実行結果

  7. copy on write の罠 • 代入の時にコピーせず、値が更新(update ≒ on write)された時にコピー(copy)する方式。 • for ループ • $x をオブジェクト参照だとすれば、オブジェクト指向プログラミングだと、結構ありがち。 • PHP4 では ushort (16bits)だよね。。。

  8. もうひとつ増やしてみよう • +1 • えっ?

  9. \(^o^)/ • さらに +1   なんてこったい /(^o^)\

  10. PHP5 では大丈夫? • unsigned int (大抵 32 bit) でも結局溢れるんじゃ?   ↓試してみました

  11. 65536*65536 の結果 • メモリが溢れました  ですよね~www 実質的に問題ない。(はず)

  12. PHP の最近(?) • PHP-5.3 以降 cycle collector の実装が入りましたhttp://php.net/manual/ja/features.gc.collecting-cycles.php

  13. zend_gc.c • Static で grep してみる • それっぽいのが入ってました。(root とか mark とか grey とかそれっぽい。中身は機会があれば)

  14. これって本当にいるの? • php のプロセスの寿命はどうせ、1 request サイクル • よほど変なコーディングをしないと、循環参照で問題にならないよね • バッチでは… 結構問題になるけど。

  15. 課題 • パフォーマンステスト • apache 上で動かす時と、コマンドラインとで切り替えられないのかな • でも、PHP 5.3 なんて使うの当分先なので、いいやw

  16. 以上です • ご静聴、ありがとうございました.

More Related