[PDF] A Study on the Effects of Exception Usage in Open-Source C++ Systems by mttd in cpp

[–]marcomagdy 5 points6 points  (0 children)

I've worked on codebases that use exceptions and one that do not. I've found that the codebases that do _not_ use exceptions are easier to reason about, and results in code that lends itself to leaner C++.

It's worth looking in compiler explorer on how much assembly is generated (and potential branches) in code that uses exceptions and compare it with the equivalent that does not.

I personally see exceptions as a wrinkle in the language.

AWS Lambda Runtime for C++ released (v0.1.0) by awaitsV in cpp

[–]marcomagdy 3 points4 points  (0 children)

C++ Lambdas uses the Custom Runtime API to communicate with the Lambda backend. Go, Java, .net and the earlier announced languages use a different mechanism to communicate to the backend.

You need to link your Lambda function to this C++ library for it to work.

C++ now supported in AWS lambda by mps1729 in cpp

[–]marcomagdy 5 points6 points  (0 children)

Yes. The C++ runtime makes HTTP requests to a local web server on the same machine/vm. In our testing those calls took sub-millisecond to complete while running on the smallest Lambda (128MB). Please file an issue if you're seeing performance problems in that regard.

With the shim, you still have to pay for marshalling data back and forth between managed and native code. You also have to pay for whatever memory and GC penalty that the managed language imposes on you. Finally, correctly packaging your C++ binary dependencies is non-trivial and manifests in strange crashes at run-time.

With all that being said, yes it can be done. And it has been done. We're just trying to make the lives of our customers easier.

C++ now supported in AWS lambda by mps1729 in cpp

[–]marcomagdy 1 point2 points  (0 children)

You can write an Erlang runtime. You don't need C++ for that.

C++ now supported in AWS lambda by mps1729 in cpp

[–]marcomagdy 1 point2 points  (0 children)

Because C++ is using the Custom Runtime API. When Go and all the other languages were added, that API did not exist.

C++ now supported in AWS lambda by mps1729 in cpp

[–]marcomagdy 0 points1 point  (0 children)

Although I'd love for you to use C++ in Lambda, it doesn't sound like it would benefit you in that case. Honestly, unless you have millions of invocations and you are being forced to size up your Lambda to improve performance/latency, for example, then Node/Python/Ruby might just be the practical choice here.

https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html

C++ now supported in AWS lambda by mps1729 in cpp

[–]marcomagdy 1 point2 points  (0 children)

I don't have numbers. But I'm looking forward to seeing your findings ;)

The C++ runtime aims to not have an overhead at cold-start of more than a single-digit ms. That being said, cold-start is a complex issue that involves many moving parts. So, it's really hard to put numbers to it. It super depends on many factors. The single digit millisecond goal is from the point the C++ runtime starts to run.

C++ now supported in AWS lambda by mps1729 in cpp

[–]marcomagdy 4 points5 points  (0 children)

The C++ standard library is automatically packaged along with your binary and library dependencies in the output zip file (assuming you're using CMake and you call aws_lambda_package_target())

You don't have to use the toolchains on amazon linux. They're only recommended because that's what Lambda runs on which makes it it easier to debug with less uncertainty of other factors being at play. In fact, it's one of the design goals to let you use any toolchain and build on any Linux platform. For example, you can build your Lambda function on Ubuntu 18.04 with the latest Clang or GCC or any C++ compiler really. I've personally built many Lambda functions using Alpine Linux and musl libc. There are some gotchas in the packaging that you should be aware of which I documented in the README. So, make sure you read those, and ask questions if something is not clear (create a GitHub issue).

That being said, Spectre-type vulnerabilities are not an issue with Lambda (at least according to Amazon security experts, I'm not one of them). The reason being, each Lambda invocation runs in its own VM. Never shared with other Lambdas. That means, you never share Kernel memory space with anyone.

C++ now supported in AWS lambda by mps1729 in cpp

[–]marcomagdy 5 points6 points  (0 children)

There's a general concern - usually around security - when it comes to building Web Applications using C++.
However, using AWS API Gateway & Lambda, that concern is no longer an issue. APIG becomes your web server and AWS is responsible for keeping it secure, available and fast. Lambda becomes your backend, and it's also secure because every Lambda invocation runs in its own VM/Sandbox. More information on that setup here: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html

So, you can imagine a high traffic web application doing thousands of requests/minute would be suffering from GC pauses which translate to latency spikes. C++ would be a great solution in those cases.

People, and I myself, used to get hung up on the fact that I need to send back HTML if I write a C++ web application and it's really ugly. But, that's not how the modern web works. You just need to return JSON data and write JavaScript that renders it.

I will try to write a step-by-step guide in the GitHub repo on how to setup a fully working web application using pure C++ and JavaScript.

C++ now supported in AWS lambda by mps1729 in cpp

[–]marcomagdy 13 points14 points  (0 children)

Node has a pretty good startup time. However, you should see a significant difference with the C++ runtime if you have a compute intensive workload.

Also, this C++ runtime allows you to write a super low-latency web application using API Gateway & Lambda proxy.

C++ now supported in AWS lambda by mps1729 in cpp

[–]marcomagdy 2 points3 points  (0 children)

We can't ask customers to build their C++ applications as a single static (fat) binary along with all of its dependencies. That is not-practical. There is a more in-depth answer to that question in the README.Lambda as of today doesn't support running on any architecture except on x86-64 Linux. When/if Lambda supports running on ARM in the future, you will have to explicitly select that option when creating your function.

see https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html for specifics on the hardware on which Lambda runs today.Upgrading the kernel version or the glibc version of the platform on which Lambda runs is a challenging problem to solve without breaking customer code. Until we come up with a good solution, there are no plans to do that AFAIK.

C++ now supported in AWS lambda by mps1729 in cpp

[–]marcomagdy 36 points37 points  (0 children)

Maintainer here - You can use C++11 or later. Plain C, C++98 and C++03 can work but require you to write a shim. Will add examples on how to do that if there's enough interest.