2012

1. Coming to a Server Near You

1. Coming to a Server Near You

p 20 /
p 21 nodes.js เป็น server-side js , deliberateตั้งใจ ให้ minimalist core library ใน rich ecosystem
run atop V8 js engine
built on chrome , event-driven , non-blocking I/O , data-intensive real-time application run across distributed devices
p 22 js as server-side – support – continuous integratio , continuous deployment , connect to relational database , service-oriented architecture
fast กว่า other script langauge eg Ruby , Python
เร็วกว่า python 13 times, กว่า rube 8 times
เพราะมัน – compilation to machine code pre-execution
โดยทั่วไป tranditional , program จะเป็นแบบ synchronous , คือ system รอให้ result แล้ว code ค่อย run ต่อ
ทำให้เกิด รอนาน
language Java , C# จึงแก้ด้วย – new thread
thread programming – ยาก เพราะ multiple thread can trying access same resource concurrently
ถ้าไม่ได้ dissecting intricaciesความซับซ้อน of multiple thread – อาจจะเกิด diastrous จาก one thread ที่วิ่งเข้ามา และอื่นๆ ก็ค่อยๆสะสม

p 23 js แก้ปัญหาแบบใหม่ – only single thread , แต่มันไม่รอ , เพราะมันจะ continue next line of code ไปเลย
แต่เมื่อ i/o operation return – มันจะ trigger callback fn
และถ้า เกิด counterintuitive , – rest
ดังนั้น จึงเป็น simple ,fast, event-drive , asynchronous ,
Strengths and Weaknesses