Sky Archive

자격증/AWS Developer Associate

[AWS] Certified Developer Associate Dump 문제 009

Anchovy ʕ-᷅ᴥ-᷄ʔ 2021. 8. 9. 21:00

A Developer has implemented a Lambda function that needs to add new customers to an RDS database that is expected to run hundreds of times per hour. The Lambda function is configured to use 512MB of RAM and is based on the following pseudo code:

After testing the Lambda function, the Developer notices that the Lambda execution time is much longer than expected. What should the Developer do to improve performance?

 

A. Increase the amount of RAM allocated to the Lambda function, which will increase the number of threads the Lambda can use.

B. Increase the size of the RDS database to allow for an increased number of database connections each hour.

C. Move the database connection and close statement out of the handler. Place the connection in the global space.

D. Replace RDS wit Amazon DynamoDB to implement control over the number of writes per second.


개발자는 시간당 수백 번 실행될 것으로 예상되는 RDS 데이터베이스에 신규 고객을 추가해야 하는 람다 기능을 구현했다. 그 람다 함수는 512MB의 RAM을 사용하도록 구성되었으며, 다음과 같은 사이비코드를 기반으로 한다.

람다 함수를 테스트한 후 개발자는 람다 실행 시간이 예상보다 훨씬 길다는 것을 알게 된다. 개발자는 성능 향상을 위해 무엇을 해야 하는가?

 

A. 람다 함수에 할당된 RAM 양을 늘리면 람다가 사용할 수 있는 스레드 수가 증가한다.

B. RDS 데이터베이스의 크기를 늘려서 매시간 데이터베이스 연결 수를 늘리십시오.

C. 데이터베이스 연결 및 닫기 문을 처리기에서 이동하십시오. 글로벌 공간에 연결을 배치하십시오.
D. 초당 쓰기 수에 대한 제어를 구현하기 위해 RDS를 Amazon DynamoDB로 대체한다.


정답↓

더보기

C.

람다 함수의 초기화 단계에서 db 연결을 초기화해야 합니다. 그러나 연결을 하나만 만드는 대신 연결 풀을 만드는 것이 좋습니다.

 

You are suppose to initialize db connection in the initialization phase of the lambda function. better yet, create a connection pool instead of just 1 connection.
https://www.jeremydaly.com/reuse-database-connections-aws-lambda/

 

함수가 다시 호출될 때 추가 최적화를 제공하기 위해 람다 함수 핸들러 코드 외부에 데이터베이스 연결 및 기타 개체/변수를 선언하십시오. 코드를 만들기 전에 코드에 로직을 추가하여 연결이 이미 있는지 확인하십시오.

 

Declare database connections and other objects/variables outside the Lambda function handler code to provide additional optimization when the function is invoked  again. You can add logic to your code to check if a connection already exists before creating one.

https://www.simform.com/aws-lambda-performance/