720 likes | 795 Views
Complex Azure Functions. What is the biggest problem with AWS Lambda?. “Arc helps you share code between AWS functions”. This is not a problem in azure!. A little about me. 8 Years in the tech industry I work @ cargurus Mostly on web performance problems I <3 cloud!.
E N D
A little about me • 8 Years in the tech industry • I work @ cargurus • Mostly on web performance problems • I <3 cloud!
What my mom thinks I do What I think I do What I actually do
Dream of the cloud • Pretend its 2008 again • “In the future the cloud is going to be awesome” • “You will only pay for what you use” • “Focus on just your apps, let msft/amazon/google manage the infra” • “Things will just magically scale” • Erhmagard Microsoft is taking our jerbs
Reality of the cloud so far • Many “lift and shifts” cost more than co-locations • Applications need to be “Cloud Native” to see benefits • You do have to care about the infrastructure • App svc is “IIS as a service” • AKS is kubernetes as a service • Things do not magically scale, you have to configure them • Typically we’ve paid for compute units even if we’re not fully utilizing them
Azure App Service • IIS as a service • You still have to care what modules are installed by default • You pay per instance • S1 -> 1 CPU 2GB ram • S2 -> 2 CPU 4GB ram • You are always under utilizing the hardware or over utilizing causing scaling
Azure Scale sets • Basically VM’s as a service • Need to be hooked up to load balancers • Need to be managed with Configuration as a service
AKS • You have to know how kubernetes works • Still need to configure autoscaling • Have to worry about cluster capacity
What is azure functions? • “Functions as a service” • Azure’s serverless offering • Although serverless does not mean no servers • Functions trigger on an event • Write a function, azure will run and scale it • You pay only for the milliseconds you use • Billing info coming later ^_^ • Azure will scale these in a linear fashion • Play very well with Logic Apps!
Functions support • Support any dotnet language (C#, F#, VB) • JavaScript • Java • Docker containers (non-consumption)
Characteristics of functions • Ephemeral • Event driven • IO calls are Non-blocking • Stateless
What is not good for functions • Functions that require a large in-memory cache • This can be mitigated with Memcached, redis or other distributed cache • Things that need persistent open connections • Websocket servers • IRC servers • SSH bastion hosts • Low latency concerns • Trading applications
Gotchas with functions • “Double billing” • Make HttpClient static in C# • 300 bound sockets • 600 coming soon! • Large JavaScript functions can load slow • Webpack • Write defensively • Poison Queue messages
Traditional infra Image Upload Return ok! Server process
Serverless infra Image Upload Return token Finish Processing Done/Not Done Check Status
Durable functions • Stateful functions • Define workflows with other functions • Checkpoint workflows • Not billed on a consumption model!
Durable functions Use cases • Complex workflow of functions • Functions that can pause and resume
Pricing • Consumption • Execution Time • Execution Units • Durable • Pre-pay (app service)
Consumption model breakdown • Execution units • Number of executions • First 1 million free • Price per $0.20/per 1 Million • Execution time • Measured in GB seconds • 400,000 GB seconds free
What is GB-s? • Observed resource consumption is calculated by multiplying average memory size in gigabytes by the time in milliseconds • Memory used by a function is measured by rounding up to the nearest 128 MB, up to the maximum memory size of 1,536 MB, with execution time calculated by rounding up to the nearest 1 ms. • The minimum execution time and memory for a single function execution is 100 ms and 128 mb respectively.
Penny Pinching • Pay for your functions • Storage blob reads/writes • Egress bandwidth
Cloudflare • Content Distribution Network (CDN) • Cache responses from http requests • Cache images/scripts/etc. • Cache redirects • Cache-Control • max-age • expires • etag • Workers are like azure functions on the edge ($5/mo)
Pwned Passwords • Type in a password • Tells you if that password is in a data leak • Completely serverless • Azure functions • Cloudflare • Azure Blob storage • K-Anonymity
K-Anonymity • The first 5 characters of the password are hashed • The function receives the hash and return a text file of all of the hashes that start with that character • The browser then searches that file for the exact record • No transmission of passwords
Why’s it matter • https://api.pwnedpasswords.com/range/E9354 • Function finds E9354.txt • Returns it • Cloudflare caches the file • Next time that hash will be cached!
“If you can architect things the right way you can run things in a cost effective way”
Infrastructure as code • Manually clicking in the portal isn’t enough • How do you mange thousands of functions? • What about bootstrapping non-prod environments?
ARM • JSON document that defines infrastructure • Works with all resources in azure • Support variables • Dependency workflow
Apply ARM Deploy function