upload_blob and download_blob takes 2 seconds to execute which increases execution time of our API

Mayank Arora 0 Reputation points
2025-02-19T13:21:00.3766667+00:00

This is how we are creating a pdf on azure blob storage and reading the file from Azure blob storage

upload_blob and download_blob takes 2 seconds to execute which increases execution time of our API

i tried async but it didnt reduced time. func tools caching also didnt helped

for redis caching we would need a new server

import logging
import os
from azure.storage.blob import ContainerClient
from starlette.config import Config
from datetime import timedelta
from datetime import datetime
import pytz

class azure_storage_account:
    def __init__(self, azure_storage_connection_string="",container_name =""):
        dir_path = os.getcwd()
        config = Config(dir_path + os.sep + '.env')
        if azure_storage_connection_string == "":
            self.azure_storage_connection_string = config('AZURE_STORAGE_CONNECTION_STRING')
        else:
            self.azure_storage_connection_string = azure_storage_connection_string

        if container_name == "":
            self.container_name = config('AZURE_API_FILE_CONTAINER')
        else:
            self.container_name = container_name
        
        self.container_client = ContainerClient.from_connection_string(conn_str=self.azure_storage_connection_string,container_name=self.container_name)


    def create_file(self,file_path,data=""):
        try:
            blob_client = self.container_client.get_blob_client(file_path)
            blob_client.upload_blob(data,overwrite=True)
            return True
        
        except Exception as e:
            logging.error(e)
            return False


    def read_file(self,file_path):
        try:
            file_stream =  self.container_client.download_blob(file_path)
            file_content = file_stream.readall()
            return file_content
        
        except Exception as e:
            logging.error(e)
            return False

Azure SQL Database
Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
667 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,440 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,095 questions
Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
1,932 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vinodh247 28,211 Reputation points MVP
    2025-02-19T16:08:13.5866667+00:00

    Hi ,

    Thanks for reaching out to Microsoft Q&A.

    Few pointers from my side to check:

    • Even though you mentioned trying async, ensure you're using the azure-storage-blob async client.
    • Azure Storage supports chunked uploads, which can speed up large file transfers.
    • use parallel execution with concurrent.futures
    • If you're dealing with logs or sequential data appends, consider AppendBlob instead of BlockBlob

    Please feel free to click the 'Upvote' (Thumbs-up) button and 'Accept as Answer'. This helps the community by allowing others with similar queries to easily find the solution.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.