-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pre-import cdk libraries at the beginning of cluster create and update
Import of cdk libraries at lambda cold start takes 12 to 16 seconds, sometimes causing lambda timeout. Importing them in a separate thread, started at the beginning of create and update operations and executed concurrently with stack validation allows to reduce the time to complete the operation.
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import logging | ||
import time | ||
from threading import Thread | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
def import_cdk(): | ||
"""Import cdk libraries.""" | ||
LOGGER.info("Start importing") | ||
begin = time.time() | ||
from aws_cdk.core import App # noqa: F401 pylint: disable=import-outside-toplevel | ||
|
||
from pcluster.templates.cluster_stack import ClusterCdkStack # noqa: F401 pylint: disable=import-outside-toplevel | ||
|
||
LOGGER.info("Import complete in %i seconds", time.time() - begin) | ||
|
||
|
||
def start(): | ||
""" | ||
Import cdk libraries in a separate thread. | ||
:return: thread importing cdk libraries | ||
""" | ||
thread = Thread(target=import_cdk) | ||
thread.start() | ||
return thread |