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  Establish Consistent Business Language And Improve Trust In Your Data

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  Schools Turn To Google Cloud To Help Re-Open Campuses

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
    Just make it scale: An Aurora DSQL story
    • May 29, 2025
  • 2
    Reliance on US tech providers is making IT leaders skittish
    • May 28, 2025
  • Examine the 4 types of edge computing, with examples
    • May 28, 2025
  • AI and private cloud: 2 lessons from Dell Tech World 2025
    • May 28, 2025
  • 5
    TD Synnex named as UK distributor for Cohesity
    • May 28, 2025
  • Weigh these 6 enterprise advantages of storage as a service
    • May 28, 2025
  • 7
    Broadcom’s ‘harsh’ VMware contracts are costing customers up to 1,500% more
    • May 28, 2025
  • 8
    Pulsant targets partner diversity with new IaaS solution
    • May 23, 2025
  • 9
    Growing AI workloads are causing hybrid cloud headaches
    • May 23, 2025
  • Gemma 3n 10
    Announcing Gemma 3n preview: powerful, efficient, mobile-first AI
    • May 22, 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
  • Understand how Windows Server 2025 PAYG licensing works
    • May 20, 2025
  • By the numbers: How upskilling fills the IT skills gap
    • May 21, 2025
  • 3
    Cloud adoption isn’t all it’s cut out to be as enterprises report growing dissatisfaction
    • May 15, 2025
  • 4
    Hybrid cloud is complicated – Red Hat’s new AI assistant wants to solve that
    • May 20, 2025
  • 5
    Google is getting serious on cloud sovereignty
    • May 22, 2025
  • /
  • Technology
  • Tools
  • About
  • Contact Us

Input your search keywords and press Enter.