Thuta Learning
Cloud & Deployment
IntermediateDevOps & Toolsbeginner

Serverless နှင့် Edge Computing

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Serverless နှင့် Edge Computing concept ကို နားလည်ရှင်းပြနိုင်ရန်
  • Diagram ကို ဖတ်ပြီး architecture ထဲမှာ request/data ဘယ်လိုစီးဆင်းသလဲ ခြေရာခံနိုင်ရန်
  • ကိုယ့် project အတွက် ဘယ်လို ဆုံးဖြတ်သင့်သလဲ ရှင်းပြနိုင်ရန်

နားလည်ထားရမယ့် အချက်

"Serverless" ဆိုတာ လှည့်ဖြားနေတဲ့ နာမည်တစ်ခုပါ — server တွေက ရှိနေဆဲ၊ code ကိုလည်း run ပေးနေဆဲပါ။ ပြောင်းလဲသွားတာက ဘယ်သူက ကိုင်တွယ်လဲဆိုတဲ့ အချက်ပါ — provision, patch, scale တွေကို သင့်အစား platform က လုပ်ပေးပါတယ်။

Developer က function တစ်ခု ပေးလိုက်ရုံပါ၊ platform က on demand run ပေးပြီး instance ကို automatic scale လုပ်ကာ idle server time မဟုတ်ပဲ တကယ့် usage အလိုက် bill ချပါတယ်။ ဒီ pay-per-use model က serverless ရဲ့ appeal အကြီးဆုံးတစ်ခုပါ။

  • Cold start – function တစ်ခု idle နေပြီးနောက် ပထမဆုံးအကြိမ် run တဲ့အခါ platform က initialize လုပ်နေစဉ် ကြုံရတဲ့ delay
  • Execution time နဲ့ resource limit တွေရှိပေမယ့် provider အလိုက်နဲ့ အချိန်နဲ့ ပြောင်းနေလို့ number memorize မလုပ်ပဲ documentation လက်ရှိကို စစ်ပါ

Edge computing ကတော့ code ကို central location တစ်ခုတည်းမှာမဟုတ်ပဲ user တွေနဲ့ physically ပိုနီးတဲ့ location များစွာမှာ run ပေးလို့ network distance ကို ဖြတ်တောက်ပေးပါတယ် — central database တစ်ခုတည်းဆီ round trip နှေးနေတုန်း ဆက်စောင့်နေရရင်တော့ workload အားလုံး အကျိုးမရှိနိုင်ပါ။

text
SERVERLESS AND EDGE COMPUTING
-----------------------------
Request --> [ Function runs on-demand ] --> Response
             (platform manages the servers)

TRADITIONAL SERVER VS EDGE LOCATION
-------------------------------------
User (Yangon) ----------------> Server (far away region)
                 (long trip, slower)

User (Yangon) --> Edge Location (nearby) --> Response
                 (short trip, often faster)

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

Workload တစ်ခုက bursty ဒါမှမဟုတ် server တစ်ခုကို အဆက်မပြတ် run ထားစရာမလိုအောင် ရှိရင် serverless ကို ရွေးပါ — webhook event တစ်ခါတစ်ရံ ကိုင်တွယ်တာ၊ image resize လုပ်တာ၊ တစ်နေ့တစ်ကြိမ် task run တာစသည်။

Persistent connection၊ အချိန်ကြာကြာ run ရမယ့် job၊ request တိုင်းအတွက် low latency လိုအပ်တဲ့ ကိစ္စတွေအတွက်တော့ အသင့်တော်နည်းပါတယ်၊ ဘာလို့ဆိုတော့ cold start က always-on server မှာ ဘယ်တော့မှ မရှိမယ့် delay တစ်ခါတစ်ရံ ဖြစ်စေလို့ပါ။

Request တစ်ခုကို အနီးအနားက ရရှိနိုင်တာနဲ့ပဲ ဖြေရှင်းလို့ရရင် edge computing ကို ရွေးထိုက်ပါတယ် — cache လုပ်ထားတဲ့ response တစ်ခု၊ auth header စစ်ဆေးခြင်းလိုမျိုး။ Call တိုင်းမှာ central database တစ်ခုတည်းကနေ data အသစ်ဖတ်ရမယ့် logic အတွက်ကတော့ အကျိုးနည်းပါတယ်။

ဒီ lesson က concept level မှာသာ တမင်ထားထားပါတယ် — Lambda function တစ်ခု တကယ်ရေး၊ deploy လုပ်၊ ချိတ်ဆက်တာကို ဒီဆိုက်ရဲ့ AWS Fundamentals tutorial မှာ လက်တွေ့ ဆွေးနွေးထားပါတယ်။

Serverless ဆိုတာ server လုံးဝမရှိဘူးလို့ မဆိုလိုပါ

Serverless function တိုင်းကို physical server တွေက အမြဲ run ပေးနေဆဲပါ — ဒီနာမည်က သင်ကိုယ်တိုင် provision/patch/manage ဘယ်တော့မှ မလုပ်ရဘူးဆိုတဲ့ အချက်ကိုသာ ရည်ညွှန်းတာပါ၊ server တွေ ကွယ်ပျောက်သွားတယ်လို့ မဆိုလိုပါ။ Cloud provider က underneath မှာ real machine တွေကို ပိုင်ဆိုင် run ပေးနေဆဲပါ။

အတူတူ စမ်းရေးကြည့်မယ်

javascript
// Illustrative only: shows the SHAPE of a serverless function handler,
// not a real deployed function on any specific platform.
function handler(request) {
  return { status: 200, body: `Hello, ${request.name}!` };
}

console.log(handler({ name: "Aye" }));
console.log(handler({ name: "Ko Ko" }));
You should see
{ status: 200, body: 'Hello, Aye!' }
{ status: 200, body: 'Hello, Ko Ko!' }
(handler() ကို data ကွဲပြားစွာနဲ့ ခေါ်တိုင်း response အသစ်ကို ပြန်ပေးတာကို သတိပြုပါ — ဒါက function shape ကိုသာ ပြသတာဖြစ်ပြီး တကယ်ဆွဲကြိုးထားတဲ့ platform မဟုတ်ပါ)

၅ မိနစ် စမ်းကြည့်

handler function ကို request.locale field ကိုပါ လက်ခံနိုင်အောင် ပြင်ပြီး တန်ဖိုးပေါ်မူတည်ပြီး Burmese ဒါမှမဟုတ် English နှုတ်ဆက်စကား ပြန်ပေးအောင် လုပ်ပါ — locale ကွဲပြားစွာနဲ့ နှစ်ကြိမ် ခေါ်ကြည့်ပြီး response မှန်ကန်စွာ ကွဲပြားလားစစ်ဆေးပါ။

သတိလေးတစ်ချက်

Serverless function တစ်ခုက invocation တစ်ခုနဲ့ တစ်ခုကြား memory ထဲ state ကို ကိုင်ထားနိုင်တယ်လို့ ထင်မှတ်တာ — invocation တစ်ခုချင်းစီဟာ instance အသစ်ပေါ်မှာ run နိုင်ပါတယ်။

Volume များစွာနဲ့ အဆက်မပြတ် run နေတဲ့ workload အတွက် serverless ကို ရွေးမိတာ — traditional always-on server က ပိုဈေးသက်သာနိုင်ပါတယ်။

Serverless Computing — WikipediaCloud & Deployment

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Serverless function တစ်ခုက invocation တစ်ခုနဲ့ တစ်ခုကြား memory ထဲ state ကို ကိုင်ထားနိုင်တယ်လို့ ထင်မှတ်တာ — invocation တစ်ခုချင်းစီဟာ instance အသစ်ပေါ်မှာ run နိုင်ပါတယ်။
  • Volume များစွာနဲ့ အဆက်မပြတ် run နေတဲ့ workload အတွက် serverless ကို ရွေးမိတာ — traditional always-on server က ပိုဈေးသက်သာနိုင်ပါတယ်။
  • Localhost မှာ အလုပ်လုပ်တာနဲ့ Production မှာ အလိုအလျောက်အလုပ်လုပ်မယ်လို့ မယူဆပါနှင့် — environment, network, database, security ကွာခြားချက်တွေ ရှိနိုင်ပါတယ်။

လေ့ကျင့်ခန်း

handler function ကို request.locale field ကိုပါ လက်ခံနိုင်အောင် ပြင်ပြီး တန်ဖိုးပေါ်မူတည်ပြီး Burmese ဒါမှမဟုတ် English နှုတ်ဆက်စကား ပြန်ပေးအောင် လုပ်ပါ — locale ကွဲပြားစွာနဲ့ နှစ်ကြိမ် ခေါ်ကြည့်ပြီး response မှန်ကန်စွာ ကွဲပြားလားစစ်ဆေးပါ။

You'll know it worked when: { status: 200, body: 'Hello, Aye!' } { status: 200, body: 'Hello, Ko Ko!' } (handler() ကို data ကွဲပြားစွာနဲ့ ခေါ်တိုင်း response အသစ်ကို ပြန်ပေးတာကို သတိပြုပါ — ဒါက function shape ကိုသာ ပြသတာဖြစ်ပြီး တကယ်ဆွဲကြိုးထားတဲ့ platform မဟုတ်ပါ)

Serverless နှင့် Edge Computing | Thuta Learning