# ประสิทธิภาพและการ Deploy บน Cloud (Node.js / NestJS) > Event loop, blocking I/O, profiling, memory leaks, การ optimize query, การบีบอัด, clustering, worker threads, load balancing, การ caching เชิงกลยุทธ์ (Redis + HTTP), AWS (ECS, Lambda), serverless, กลยุทธ์การ deploy (blue/green, canary) - 30 คำถามสัมภาษณ์ - Senior - [คำถามสัมภาษณ์: Node.js / NestJS](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions.md) ## 1. แนวทางใดที่ช่วยเพิ่มประสิทธิภาพการ deploy container NestJS ใน AWS ECS? **คำตอบ** เพื่อเพิ่มประสิทธิภาพการ deploy container NestJS บน ECS: ใช้ multi-stage Docker builds เพื่อลดขนาด image สุดท้าย (build stage + production stage แบบ minimal), ใช้ Docker layer caching เพื่อเร่งการ build, ใช้ ECR (Elastic Container Registry) ใน region เดียวกันเพื่อลด latency, ตั้งค่า health checks ที่เหมาะสม, ใช้ Fargate เพื่อให้การจัดการง่ายขึ้น, กำหนด resource limits (CPU/memory) ที่เหมาะสม, ทำ graceful shutdown สำหรับ SIGTERM อิมเมจ Node.js alpine ที่ optimize แล้วอาจมีขนาด <100MB เทียบกับ >1GB ที่ไม่ได้ optimize ## 2. เฟสหลักของ event loop ใน Node.js มีอะไรบ้าง? **คำตอบ** event loop ของ Node.js มี 6 เฟสหลัก: timers (setTimeout/setInterval), pending callbacks (I/O callback ที่ถูกเลื่อน), idle/prepare (ภายใน), poll (ดึง event I/O ใหม่), check (setImmediate) และ close callbacks แต่ละเฟสมี queue แบบ FIFO ของ callback ที่จะรัน เฟส poll สำคัญที่สุดเพราะจัดการ event I/O ## 3. การทำงานแบบบล็อก (blocking I/O) ใน Node.js ส่งผลกระทบอย่างไร? **คำตอบ** การทำงานแบบบล็อกใน Node.js จะบล็อก event loop ทั้งหมด ทำให้การทำงานอื่นๆ ทั้งหมดไม่สามารถประมวลผลได้ สิ่งนี้ทำให้ประสิทธิภาพลดลงอย่างมากเพราะ Node.js เป็นแบบ single-thread การทำงานแบบ synchronous เช่น fs.readFileSync, crypto.pbkdf2Sync หรือ loop ที่หนักจะบล็อก thread หลัก ควรใช้เวอร์ชัน asynchronous เสมอ หรือมอบหมายให้ worker threads ## มีอีก 27 คำถาม - จะระบุ memory leak ในแอปพลิเคชัน Node.js บน production ได้อย่างไร? - ควรใช้เครื่องมือใดในการ profiling ประสิทธิภาพ CPU ของแอปพลิเคชัน NestJS? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Node.js / NestJS อื่นๆ - [พื้นฐาน Node.js](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/nodejs-fundamentals.md): 20 คำถาม, Junior - [Core API ของ Node.js](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/nodejs-core-apis.md): 25 คำถาม, Junior - [การเขียนโปรแกรมแบบอะซิงโครนัส](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/asynchronous-programming.md): 25 คำถาม, Junior - [พื้นฐาน Express.js](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/express-basics.md): 20 คำถาม, Junior - [พื้นฐาน NestJS](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/nestjs-fundamentals.md): 23 คำถาม, Junior - [การออกแบบ REST API](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/rest-api-design.md): 20 คำถาม, Junior - [การตรวจสอบความถูกต้องและ DTO](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/validation-dto.md): 20 คำถาม, Junior - [เอกสาร API และ Contract](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/api-documentation.md): 20 คำถาม, Junior - [การจัดการข้อผิดพลาด](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/error-handling.md): 20 คำถาม, Junior - [การทดสอบหน่วย (Unit Testing)](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/testing-unit.md): 20 คำถาม, Junior - [การจัดตารางงาน](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/scheduling-cron.md): 15 คำถาม, Junior - [Module และ DI ของ NestJS](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/nestjs-modules-di.md): 20 คำถาม, Mid-Level - [การกำหนดค่าและการจัดการสภาพแวดล้อม](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/configuration-environment.md): 20 คำถาม, Mid-Level - [การยืนยันตัวตนด้วย JWT](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/authentication-jwt.md): 25 คำถาม, Mid-Level - [การให้สิทธิ์และ RBAC](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/authorization-rbac.md): 20 คำถาม, Mid-Level - [ฐานข้อมูลด้วย TypeORM](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/database-typeorm.md): 30 คำถาม, Mid-Level - [Prisma ORM](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/prisma-orm.md): 25 คำถาม, Mid-Level - [Middleware และ Interceptor](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/middleware-interceptors.md): 20 คำถาม, Mid-Level - [การอัปโหลดไฟล์](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/file-upload.md): 15 คำถาม, Mid-Level - [WebSockets](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/websockets.md): 20 คำถาม, Mid-Level - [GraphQL กับ NestJS](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/graphql-basics.md): 25 คำถาม, Mid-Level - [การทดสอบแบบ End-to-End](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/testing-e2e.md): 20 คำถาม, Mid-Level - [การแคชด้วย Redis](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/caching-redis.md): 20 คำถาม, Mid-Level - [คิวด้วย Bull](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/queues-bull.md): 20 คำถาม, Mid-Level - [DevOps, Logging และ CI/CD](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/logging-monitoring.md): 25 คำถาม, Mid-Level - [Docker และ Containerization](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/docker-containerization.md): 25 คำถาม, Mid-Level - [ไมโครเซอร์วิส](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/microservices.md): 30 คำถาม, Senior - [แนวทางปฏิบัติที่ดีที่สุดด้านความปลอดภัย](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/security-best-practices.md): 25 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/performance-optimization