aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • Programming
  • Public Cloud

Celebrating Pi Day With Cloud Functions

  • aster.cloud
  • March 15, 2022
  • 3 minute read

March 14 is Pi Day, an annual celebration of the mathematical constant π. We’re doing a few experiments with the new Cloud Functions (2nd gen) this year to showcase the new serverless platform.

Serverless π calculation

Can we go serverless to calculate π? There is a relatively new algorithm called the Bailey–Borwein–Plouffe formula (BBP formula) to calculate digits of π without computing the preceding digits, which means we can run many calculations in parallel and gather the results later. We can build a MapReduce pipeline to get the numbers. Cloud Functions (2nd gen) supports larger instances (16 GB memory and 4 vCPUs) and extends the max function execution duration to 60 minutes from 9 minutes so we can push the limits further.


Partner with aster.cloud
for your next big idea.
Let us know here.



From our partners:

CITI.IO :: Business. Institutions. Society. Global Political Economy.
CYBERPOGO.COM :: For the Arts, Sciences, and Technology.
DADAHACKS.COM :: Parenting For The Rest Of Us.
ZEDISTA.COM :: Entertainment. Sports. Culture. Escape.
TAKUMAKU.COM :: For The Hearth And Home.
ASTER.CLOUD :: From The Cloud And Beyond.
LIWAIWAI.COM :: Intelligence, Inside and Outside.
GLOBALCLOUDPLATFORMS.COM :: For The World's Computing Needs.
FIREGULAMAN.COM :: For The Fire In The Belly Of The Coder.
ASTERCASTER.COM :: Supra Astra. Beyond The Stars.
BARTDAY.COM :: Prosperity For Everyone.

Here’s the architecture we built. We used Node to implement the functions.

Distributed Pi

The calculation runs as follows.

  • The processRequest function to create and submit tasks (e.g., calculate X digits from offset Y) to PubSub.
  • The calculateOffset function gets triggered by PubSub, computes digits, and stores the result to Firestore.
  • A separate controller function keep-watch monitors Firestore and triggers combineResults once all tasks are complete, storing the final output in Cloud Storage as a text file.

How long does it take? It takes about 45 minutes to calculate 64 million digits.

Pi Table

Unfortunately, the BBP formula is computationally more complex than other algorithms used in record-breaking attempts (such as our last 31.4 trillion record), so it is unlikely we can use this method to establish a new record. However, the extended runtime in Cloud Functions makes running many new applications possible, including this experiment.

Read More  Verizon Connect And AWS Collaborate On Full Cloud Migration

Serverless Pi API

We’ve also built a new API to serve digits of π. We previously used Google Kubernetes Engine (GKE), but we have migrated the service to Cloud Functions 2nd gen. We also rewrote the API program to fetch data from Cloud Storage instead of Persistent Disk.

Pi API

We’ve reduced the total monthly expenses from about 9,000 US dollars to 450 US dollars by changing the architecture.

  • Storage cost: The most significant cost factor is the disk. The previous configuration used a Zonal SSD Persistent Disk to store the digits of π, and it’s 50 TB with 50 trillion digits in plain text, which costs 8,500 US dollars a month. We’ve moved all the data to Cloud Storage. We’ve also changed the object format to a compressed file so that the 50 trillion digits consume 21 TB instead of 50 TB. With these changes, storage cost is about 400 US dollars a month, which is 95% saving.
  • Compute cost: Cloud Functions also helps reduce cost. There is no base CPU cost for Cloud Functions as it only charges when processing requests. Previously with GKE, we always had four instances in 2 zones that would cost 391 US dollars per month with the e2-standard-4 instance type. We estimate that the monthly cost would be around 7 US dollars for 1 million requests, achieving 98% saving.

The new service architecture is also faster and more robust as it runs in multiple regions. The global HTTP(S) load balancer chooses the closest region automatically and improves latency. The API function has a small cache inside and returns a response without accessing the Cloud Storage bucket on a cache hit.

Read More  10 Common Behavioral Mistakes Novice Programmers Make

Live demo

We have a live demo using the new API where you can listen to music created by the digits of π or watch an animation of transitions of the numerical sequence. We host the entire 50 trillion digits from the 2021 world record for the demo. You can also call the API directly from the command line:

curl "https://api.pi.delivery/v1/pi?start=0&numberOfDigits=100"

The source code of the API service and the demo are available on GitHub. We use Terraform to manage the infrastructure, and we’ve published the scripts as well, so it’s a great place to learn with actual examples.

Happy Pi Day!

 

By Emma Haruka Iwao, Developer Advocate
Source Inside Vancouver


For enquiries, product placements, sponsorships, and collaborations, connect with us at [email protected]. We'd love to hear from you!

Our humans need coffee too! Your support is highly appreciated, thank you!

aster.cloud

Related Topics
  • Cloud Functions
  • Google Cloud
  • Pi Day
  • π
You May Also Like
View Post
  • Computing
  • Public Cloud
  • Technology

United States Army Enterprise Cloud Management Agency Expands its Oracle Defense Cloud Services

  • April 15, 2025
DeepSeek R1 is now available on Azure AI Foundry and GitHub
View Post
  • Public Cloud
  • Technology

DeepSeek R1 is now available on Azure AI Foundry and GitHub

  • February 2, 2025
Cloud platforms among the clouds
View Post
  • Computing
  • Learning
  • Public Cloud

Best Cloud Platforms Offering Free Trials for Cloud Mastery

  • December 23, 2024
Vehicle Manufacturing
View Post
  • Hybrid Cloud
  • Public Cloud

Toyota shifts into overdrive: Developing an AI platform for enhanced manufacturing efficiency

  • December 10, 2024
IBM and AWS
View Post
  • Public Cloud

IBM and AWS Accelerate Partnership to Scale Responsible Generative AI

  • December 2, 2024
COP29 AI and Climate Change
View Post
  • Public Cloud
  • Technology

How Cloud And AI Are Bringing Scale To Corporate Climate Mitigation And Adaptation

  • November 18, 2024
Cloud Workstations
View Post
  • Public Cloud

FEDRAMP High Development in the Cloud: Code with Cloud Workstations

  • November 8, 2024
View Post
  • Public Cloud

PyTorch/XLA 2.5: vLLM support and an improved developer experience

  • October 31, 2024

Stay Connected!
LATEST
  • 1
    Pure Accelerate 2025: All the news and updates live from Las Vegas
    • June 18, 2025
  • 2
    ‘This was a very purposeful strategy’: Pure Storage unveils Enterprise Data Cloud in bid to unify data storage, management
    • June 18, 2025
  • What is cloud bursting?
    • June 18, 2025
  • 4
    There’s a ‘cloud reset’ underway, and VMware Cloud Foundation 9.0 is a chance for Broadcom to pounce on it
    • June 17, 2025
  • What is confidential computing?
    • June 17, 2025
  • Oracle adds xAI Grok models to OCI
    • June 17, 2025
  • Fine-tune your storage-as-a-service approach
    • June 16, 2025
  • 8
    Advanced audio dialog and generation with Gemini 2.5
    • June 15, 2025
  • 9
    A Father’s Day Gift for Every Pop and Papa
    • June 13, 2025
  • 10
    Global cloud spending might be booming, but AWS is trailing Microsoft and Google
    • June 13, 2025
about
Hello World!

We are aster.cloud. We’re created by programmers for programmers.

Our site aims to provide guides, programming tips, reviews, and interesting materials for tech people and those who want to learn in general.

We would like to hear from you.

If you have any feedback, enquiries, or sponsorship request, kindly reach out to us at:

[email protected]
Most Popular
  • Google Cloud, Cloudflare struck by widespread outages
    • June 12, 2025
  • What is PC as a service (PCaaS)?
    • June 12, 2025
  • 3
    Crayon targets mid-market gains with expanded Google Cloud partnership
    • June 10, 2025
  • By the numbers: Use AI to fill the IT skills gap
    • June 11, 2025
  • 5
    Apple services deliver powerful features and intelligent updates to users this autumn
    • June 11, 2025
  • /
  • Technology
  • Tools
  • About
  • Contact Us

Input your search keywords and press Enter.