在 nodejs 手動 garbage collection 的方法

前陣子因為在 Heroku 上面跑的 nodejs 程式開始不斷出現記憶體使用超量的訊息:
R14 - Memory Quota Exceeded ,加錢升 dyno (Heroku 上的 instance) 也不見好轉,只好想看看有沒有什麼方法可以改善,後來作法是手動執行 garbage collection,記憶體使用量就掉下去了 …

以 cdnjs 的 api / web server 為例,沒做 gc 的話大概要吃 410 MB 的記憶體,一模一樣的程式,有做 gc 的話只要吃 230 MB的記憶體,相差甚大,其中原由大概只能等高手指教或是等很閒的時候才有空追了 …

作法滿簡單的,執行 nodejs 的時候加上 --expose-gc 的參數,並且在你想要執行 garbage collection 的地方加入 global.gc(); 即可。

Netflix 推出的 Fast.com 網路測速服務

Netflix 前幾天在他們部落格上的這篇 「Now Available Globally: Fast.com, a New Tool to Check Your Internet Speed」跟大家宣佈推出的網路測速服務:Fast.com

Fast.com 的畫面非常簡潔,只測試使用者的 “下載” 速度、不測試上傳速度,整個畫面除了測速速率以外,只有暫停 / 重新測試的按鈕,說明按鈕,以及 FAST 和 NETFLIX 的 LOGO,測試結束後會出現 Speedtest.net 的連結讓使用者方便連到 Speedtest 做參考:

目前看起來 Fast.com 比起 Speedtest 的幾個優勢:

  • 使用 https 加密連線,對使用者的隱私更加有保障 (雖然只是測速、可是為什麼要讓其他人知道?)
  • 畫面非常簡單、沒有廣告
  • 單純的 html + js 搭建出來的網頁前端 ( Speedtest 目前都還是在使用 Flash ),在手機、平版電腦或是 FreeBSD / Linux 等不支援(或是使用較困難) Flash player 的平台上都可以使用輕易透過 Chrome / Firefox 等瀏覽器直接使用,不需要另外安裝應用程式

不過現階段看起來 Fast.com 也有頻寬明顯不足的問題,除了沒有 ping 值參考外,有別於 Speedtest 是透過多方合作的模式在各地建立測試點, Fast.com 目前看起來是丟在Amazon S3 上面走 Akamai 的網路,我以下載速率 1 Gbps 的網路多次使用 Fast.com 測試結果只跑的到 140 Mps 上下, 同樣的網路環境 Speedtest.net 則是落在 900~950 Mbps 的區間,如果說 Netflix 只是要提供自己的用戶測試存取自家服務的網路頻寬的話還算是有參考價值,但如果要真的拿來確認所在網路的對外頻寬的話看起來現在還不能拿來當作參考 …

PS: Speedtest.net 其實也有提供 html5 的測試版本,有興趣的人可以連到這個網址玩玩看:http://beta.speedtest.net/ ,不過目前沒有開放給行動裝置使用,使用手機連上去會直接跳 Android / iOS / Windows Phone 這幾個平台的 APP 下載連結給你 (連偵測一下使用者系統只顯示對應的連結都沒做 … 可能是因為在 beta 吧) ,相對有點可惜,希望未來可以開放給行動裝置使用 (不然你改用 html5 只是為了避免未來被各家瀏覽器直接封鎖而已嗎? 可攜性就這樣白費了!)。

 

租屋注意事項筆記

差不多又到了學生在外找租屋的季節(?)了,為了避免自己忘東忘西,所以就做了一些筆記,不用每次找房都要想半天,除了租金以外,有哪些東西是應該列入考量或是可以列入考量的,既然有整理出一些東西,也就順便分享給大家參考。

住處週邊考量:

  • 噪音
    • 跟大馬路或商圈的距離等
  • 整潔
  • 週邊生活機能
  • 交通便利性
    • 公車、客運、火車、捷運、高鐵、社區巴士等
    • 缺乏公共交通工具、但離學校或公司距離近也是很好

公共設施、住戶服務:

  • 有無管理員常駐?可否代收信件、包裹?
  • 有無提供飲水機?
    • 只有熱水? 還是冷/溫水+熱水?  冰+溫+熱水?
    • 有無定期更換濾心?
  • 有無提供冰箱?
    • 有無定期清理?
  • 有無提供洗衣機、烘衣機、脫水機?
    • 有無定期清洗?
  • 有無公共空間、電梯、出入口等地點有無監視器?
  • 是否有停放汽、機車位?
    • 室內?室外?
  • 有無晾衣間、曬衣場?
    •  室內?室外?
  • 有無陽台?
  • 有無門禁管理?
  • 有無微波爐?
  • 公共空間是否定期打掃?
  • 有無滅火器?
  • 有無緊急照明燈?

閱讀全文

Remove Exif info in jpg image under command line

Exif, stands for Exchangeable image file format, which we usually use to recognize the camera manufacturer, model, exposure time in a digital photo, it is a standard that specifies the formats for images, sound, and ancillary tags used by digital cameras (or digital devices in nowadays, like smart phones and tablets), scanners and other systems handling image and sound files recorded by digital cameras.

Exif in JPEG image example from Wikipedia: https://en.wikipedia.org/wiki/File:Konqueror_Exif_data.jpg

Exif can help us know more about the photos and audios, but may also leaks the valuable and privacy info if you don’t want to let others know that you just want to share pictures with others, it will also cost a small disk space, but if you don’t need it or you don’t want it, it’s also a waste of disk space, so you may want to remove that info like me in some situation. Here is the steps to remove Exif under command line.

Install exiftool:

$ sudo pkg install p5-Image-ExifTool # FreeBSD
$ sudo apt-get install libimage-exiftool-perl # Debian / Ubuntu based GNU/Linux
$ sudo yum install perl-Image-ExifTool # RedHat / Fedora based GNU/Linux

Make sure you can now use exiftool:

$ exiftool -ver # show the installed version of exiftool
9.46

If you would like to see the current exist info, use this command, filename.jpg is the picture you want to manipulate:

$ exiftool -all filename.jpg

Now you can remove Exif info:

$ exiftool -all= filename.jpg

By default, it will backup your file to filename_oringinal, like filename.jpg -> filename.jpg_original, so you don’t need to worry about the backup, if you don’t want it, you can also add parameter -overwrite_original to prevent to backup file been generated.

After you remove the Exif info, you will find the modified file be a little bit smaller now.

$ exiftool -all= filename.JPG
1 image files updated

$ ls -l
-rw-r--r-- 1 peter peter 1609796 Apr 24 16:09 filename.jpg
-rw-r--r-- 1 peter peter 1614079 Apr 24 16:08 filename.jpg_original

If you take a look at its info, you will find that there are only some basic info remaining:

$ exiftool -all filename.jpg
ExifTool Version Number : 10.10
File Name : DSC_0470.JPG
Directory : .
File Size : 1572 kB
File Modification Date/Time : 2016:04:24 16:09:43+08:00
File Access Date/Time : 2016:04:24 16:09:43+08:00
File Inode Change Date/Time : 2016:04:24 16:09:43+08:00
File Permissions : rw-r--r--
File Type : JPEG
File Type Extension : jpg
MIME Type : image/jpeg
Image Width : 3920
Image Height : 2204
Encoding Process : Baseline DCT, Huffman coding
Bits Per Sample : 8
Color Components : 3
Y Cb Cr Sub Sampling : YCbCr4:2:0 (2 2)
Image Size : 3920x2204
Megapixels : 8.6

That’s all.