1
00:00:00,270 --> 00:00:07,470
In this video, we are going to learn concurrency on a lambda result and provision concurrency.

2
00:00:08,440 --> 00:00:13,840
So I would like to start with the memory and time and configuration optimization.

3
00:00:14,020 --> 00:00:20,650
In the last video we learned configurations of a lambda function and one of the important configuration

4
00:00:20,650 --> 00:00:23,560
was the memory and timeout configurations.

5
00:00:24,040 --> 00:00:32,320
The memory settings determines how much CPU power will receive for our lambda function and higher CPU

6
00:00:32,320 --> 00:00:35,050
power decreased the function execution time.

7
00:00:35,950 --> 00:00:41,650
And we can configure timeout value in order to balance enough time to our function to complete.

8
00:00:41,800 --> 00:00:48,820
And we should set the timeout really carefully because one function which to timeout value and not finished

9
00:00:48,820 --> 00:00:52,090
lambda for beastly stop the execution.

10
00:00:52,760 --> 00:00:59,390
Since function calls is tied to memory allocation and the execution time, we should set the memory

11
00:00:59,390 --> 00:01:02,970
and the timeout configuration according to our use case.

12
00:01:02,990 --> 00:01:08,900
This will optimize our cost and maximize our service competing with lambda functions.

13
00:01:10,040 --> 00:01:15,060
So after that, we have understand the configurations of lambda functions.

14
00:01:15,080 --> 00:01:19,550
Now we can go further to advanced concepts, which is the concurrency.

15
00:01:20,060 --> 00:01:26,690
Concurrency is the number of instances of our function that are actively executing a list is lambda

16
00:01:26,690 --> 00:01:29,750
provides two types of concurrency controls.

17
00:01:30,050 --> 00:01:34,550
One is the reserved concurrency, and second is the provision concurrency.

18
00:01:35,390 --> 00:01:37,820
And we can manage the resort concurrency.

19
00:01:37,850 --> 00:01:41,150
Let me start with explaining what is the concurrency?

20
00:01:41,810 --> 00:01:47,810
Concurrency is the number of requests that are function is working at any given time, but none of the

21
00:01:47,810 --> 00:01:48,980
function is invoked.

22
00:01:49,010 --> 00:01:54,830
Lambda allocates an instance of our functions in order to process the incoming event.

23
00:01:55,460 --> 00:01:59,720
When the function code is finished to running, it can handle another request.

24
00:01:59,810 --> 00:02:06,890
If the function is invoked again, while a request is still being processed, another instance is allocated

25
00:02:06,890 --> 00:02:09,500
which increases the functions concurrency.

26
00:02:10,610 --> 00:02:17,120
The total concurrent number of lambda functions in our account is subject to per region quota.

27
00:02:17,570 --> 00:02:21,920
So we said that there are two types of concurrency controls are available.

28
00:02:22,070 --> 00:02:23,660
Let me start one by one.

29
00:02:23,900 --> 00:02:27,110
I would like to start with the concurrency result.

30
00:02:27,110 --> 00:02:31,850
Concurrency guarantees the maximum number of concurrent instance for our function.

31
00:02:31,850 --> 00:02:36,830
When a function has resolved concurrency, no other function can use that concurrency.

32
00:02:36,830 --> 00:02:40,940
There is no charge for configuring result comprehensive for the function.

33
00:02:41,820 --> 00:02:46,200
And we can configure resolve concurrency from a management console.

34
00:02:46,230 --> 00:02:53,220
If you go to a lambda console and open the function page and choose the function and go to configuration

35
00:02:53,220 --> 00:02:56,040
page, that should be a concurrent setup.

36
00:02:56,070 --> 00:03:01,800
Under the concurrent setup, we can set the reserved concurrency and enter the amount of the concurrency

37
00:03:01,800 --> 00:03:03,640
to resolve that function.

38
00:03:03,660 --> 00:03:06,000
For example, we can set 100.

39
00:03:06,630 --> 00:03:09,870
We can also throttle the function.

40
00:03:10,320 --> 00:03:13,830
So this is one of the important features to go through the function.

41
00:03:14,280 --> 00:03:18,750
In order to throw to a function, we can set the result concurrency to zero.

42
00:03:18,900 --> 00:03:23,730
This stops any events from being processed until we remove the limit.

43
00:03:23,760 --> 00:03:28,360
This is a good way to suddenly stop our executions on environment.

44
00:03:28,380 --> 00:03:34,740
For example, if your function is getting errors for all invocations, we can suddenly shut down the

45
00:03:34,740 --> 00:03:38,310
executions by setting concurrency as a zero.

46
00:03:40,110 --> 00:03:42,300
As you can see the image on the slide.

47
00:03:42,420 --> 00:03:48,150
There are two functions with pools of reserve concurrency and unresolved concurrency pools used by another

48
00:03:48,150 --> 00:03:48,870
function.

49
00:03:49,080 --> 00:03:54,050
Throttling errors occurs when all the concurrency input in use.

50
00:03:54,060 --> 00:04:01,650
You can see these lines are errors because these is the limit of the are executions concurrent executions.

51
00:04:01,650 --> 00:04:04,260
And that's why this is the throttling by a.

52
00:04:06,170 --> 00:04:12,460
Look, we can also set result concurrency configuration with using the commands.

53
00:04:12,560 --> 00:04:15,980
We can use the put function concurrent to command.

54
00:04:16,010 --> 00:04:19,070
You can see the example command command on the slide.

55
00:04:19,100 --> 00:04:23,390
Command is set to resort concurrency as a 100.

56
00:04:23,570 --> 00:04:30,170
And this is using the output function Concurrency Command with the Ada Lovelace Lambda SLI command and

57
00:04:30,170 --> 00:04:37,640
it is return back to us result, concurrency, execution result and it is return back to 100 again.

58
00:04:39,200 --> 00:04:44,910
Look, now, I would like to talk about the adverse lambda provision concurrency as you remember that

59
00:04:44,910 --> 00:04:49,770
this is the second type of concurrency control provision concurrency.

60
00:04:49,790 --> 00:04:56,540
Initialize a requested number of execution environments so that they are prepared to respond immediately

61
00:04:56,540 --> 00:04:58,160
to our function invocation.

62
00:04:58,160 --> 00:05:01,040
So provision concurrency is a name suggested.

63
00:05:01,070 --> 00:05:08,720
We can get the provisioned environment before we invocation happened and these will be prepared.

64
00:05:08,720 --> 00:05:13,280
Initialize the request incoming events and prepared for that environment.

65
00:05:13,280 --> 00:05:18,920
We should know that configuring provisioned concurrency incurs charge to our account.

66
00:05:19,740 --> 00:05:25,710
If you want to decrease latency for our functions, we can use provision concurrency, but it comes

67
00:05:25,710 --> 00:05:26,610
with the cost.

68
00:05:27,480 --> 00:05:32,940
When Lambda allocates an instance of our function for the provision concurrency, the runtime loads

69
00:05:32,940 --> 00:05:39,180
are function code and run initialization code that we define outside of the handled like database clients

70
00:05:39,180 --> 00:05:39,900
and so on.

71
00:05:39,900 --> 00:05:43,140
By this way, the function will be prepared for the invocations.

72
00:05:43,500 --> 00:05:48,570
There is also one more very important topic which is the code start.

73
00:05:49,860 --> 00:05:57,660
If our code or dependencies are very large or we create SDK clients during the initial initialization,

74
00:05:57,660 --> 00:06:03,780
this process can take some time when our function has not been used for some time and needs to scale

75
00:06:03,780 --> 00:06:06,960
up or when we update the function.

76
00:06:06,960 --> 00:06:13,140
Lambda Code is a naive execution environments and these calls that some of the requests cannot be handled

77
00:06:13,140 --> 00:06:14,130
immediately.

78
00:06:14,160 --> 00:06:21,300
It takes some time to spin up the lambda function again and it makes an instance to have higher latency.

79
00:06:21,300 --> 00:06:24,240
And we also call this station is a code start.

80
00:06:24,270 --> 00:06:30,810
Code start is very important terminology when it comes to concurrency on a lambda function.

81
00:06:30,810 --> 00:06:37,350
And we should consider the how we can solve the code, start doing your executions or your function.

82
00:06:37,890 --> 00:06:44,460
So in order to solve these code start problem, we can allocate provision concurrency before an increase

83
00:06:44,460 --> 00:06:45,660
in invocations.

84
00:06:45,660 --> 00:06:52,200
We can ensure that all requests are executed by initialized instance with low latency lambda function

85
00:06:52,200 --> 00:06:58,230
configured with the provision concurrency run with the consistent setup latency and making them ideal

86
00:06:58,230 --> 00:07:04,590
for building interactive mobile and web backend and latency sensitive microservices and synchronous

87
00:07:04,590 --> 00:07:05,820
to invoked APIs.

88
00:07:06,150 --> 00:07:12,510
Lambda also integrates with application auto scaling that allowing to manage provisioned concurrency

89
00:07:12,510 --> 00:07:14,940
on a schedule or based on utilization.

90
00:07:15,330 --> 00:07:22,410
You can see auto scaling provision concurrency on the image of the slide and this is automatically scale

91
00:07:22,410 --> 00:07:27,720
and increase the appropriate concurrency in order to accommodate incoming events and invocations for

92
00:07:27,720 --> 00:07:28,980
a lambda function.

93
00:07:29,190 --> 00:07:35,940
So we can use provisioned concurrency for the solution of the code start, but it comes with the cost.

94
00:07:35,940 --> 00:07:40,740
So that's why we should consider the cost and your invocations together.
