有 Lazy Connection 功能的 PDO object

在「Aura.Sql」這邊看到有提供 Lazy Connection 的 PDO object,而且是繼承自本來的 PDO object:

Provides an extension to the native PDO along with a profiler and connection locator. Because ExtendedPdo is an extension of the native PDO, code already using the native PDO or typehinted to the native PDO can use ExtendedPdo without any changes.

Lazy connection. ExtendedPdo connects to the database only on method calls that require a connection. This means you can create an instance and not incur the cost of a connection if you never make a query.

之後可以拿來跟 LaravelEloquent 一起用看看。本來的 PDO 物件在建立時就會建立連線,對於連線的開銷其實蠻大的,用這個應該是個方向...

另外是 Profiler 的能力,需要用的時候應該會很好用:

Profiler. An optional query profiler is provided, along with an interface for other implementations, that logs to any PSR-3 interface.

引一下來源,當初是從「Atlas.Orm 2.0 Is Now Stable」這邊在看文件時一路看到的。

Valgrind 的其他用途

這篇文章的標題就說明了作者對 Valgrind 只被拿來抓 leak 很不滿:「Valgrind is *NOT* a leak checker」。

依照文章裡的說法:

Valgrind is an undefined behavior checking tool first, a function and memory profiler second, a data-race detection tool third, and a leak checking tool last.

文章裡從最簡單的用法 (什麼參數都不加) 開始解釋,到後面的 leak 檢查以及 profiling,算是還蠻清楚的 XDDD

用 perf 追蹤系統狀態

在「Make Your Program Slower With Threads」這邊看到的工具:「Linux kernel profiling with perf」。

Ubuntu 上的安裝方式是安裝 linux-tools,不過我的機器上是安裝 linux-tools-lts-raring

先從比較簡單的 stat,基本的用法很簡單,後面接指令就可以了:

perf stat ls -al

這樣會出現基本的執行狀況,像是這樣:

 Performance counter stats for 'ls -al':

         11.236723 task-clock                #    0.703 CPUs utilized          
               341 context-switches          #    0.030 M/sec                  
                 0 cpu-migrations            #    0.000 K/sec                  
               453 page-faults               #    0.040 M/sec                  
         8,186,524 cycles                    #    0.729 GHz                    
    stalled-cycles-frontend 
    stalled-cycles-backend  
        10,366,309 instructions              #    1.27  insns per cycle        
         2,122,560 branches                  #  188.895 M/sec                  
            36,979 branch-misses             #    1.74% of all branches        

       0.015977493 seconds time elapsed

更複雜的用法在 Tutorial 那篇文章裡面有說明。

測試 MySQL 效能的方法

DigitalOcean 上的教學文章看到另外一種 MySQL 效能測試的方法:「How To Measure MySQL Query Performance with mysqlslap」。

一般會拿 Perconatpcc-mysql 測,用 mysqlslap 好像比較少看到,雖然也是蠻有名的工具...

不過還是可以拿來玩玩看,互相比較的時候是一個指標...

NLP 的應用:PAN 2013

兩個禮拜前在 Slashdot 上看到的「When Writing, How Anonymous Can You Be, Really?」,提到了 PAN Workshop and Competition

PAN 2013 將在明年九月辦,除了一般有的演講以及投稿以外,還包括了三個競賽:

  • Plagiarism Detection
  • Author Identification
  • Author Profiling

三個題目都相當實用... 先紀錄起來,等明年九月再回頭來看?

sitespeed.io 網站測速

sitespeed.io 是一個 open source 軟體,讓開發者可以測試網站的效能,然後輸出 html 報表:「Do you sitespeed?」。

執行需要 Java 1.7+ 以及 PhantomJS,我是在 FreeBSD 上跑 (Java 的部份是用 java/openjdk7),另外根據文章裡第三個 comment,在 Windows 上用 Cygwin 也可以跑。

./sitespeed.io -u http://ptt.cc/ -d 1 -o img 跑出來後會有一整個目錄的報告,包括了 summary 以及所有頁面的清單 (後面這兩個連結是跑完後用 s3cmd sync 丟上 S3 的):「ptt.cc - Summary of the sitespeed.io result」、「ptt.cc - All pages information」。

每一頁都有細項說明,像是首頁 /index.html:「Page data, collected by sitespeed.io for page - http://www.ptt.cc/index.html」。

不過我更感興趣的是 PhantomJS,不知道可以做多少事情...

mctop:memcache top

mctop 其實是個看得懂 L7 packet 的 sniffer XDDD

軟體是由 Etsy 所開發,出自:「mctop - a tool for analyzing memcache get traffic」。跑起來像這樣 (官方的範例圖):

GitHub 頁面上官方有提到因為是透過 ruby-pcap,目前沒有辦法完全承載大流量 (會有 packet loss),不過看起來是 profiling 必備工具 :p