cd /news/artificial-intelligence/31-8x-speedup-by-changing-one-file-a… Β· home β€Ί topics β€Ί artificial-intelligence β€Ί article
[ARTICLE Β· art-75064] src=dev.to β†— pub= topic=artificial-intelligence verified=true sentiment=↑ positive

31.8x Speedup by Changing One File: Async Embedding Calls on AWS Bedrock

A developer achieved a 31.8x speedup in a RAG ingestion pipeline by converting sequential HTTP embedding calls to asynchronous concurrent requests using aiohttp and asyncio.gather on AWS Bedrock, reducing processing time from 49.61 seconds to 1.56 seconds with no infrastructure changes.

read2 min views1 publishedJul 27, 2026

I was testing a RAG ingestion pipeline and noticed something painful: ingesting a single document took nearly 50 seconds.

Checking the metrics revealed that the CPU was doing almost nothing. The app wasn't compute-bound β€” it was simply sitting idle, waiting for sequential HTTP network round-trips to return.

By converting the blocking embedding module into an asynchronous workflow, processing time dropped from 49.61 seconds to 1.56 seconds with zero infrastructure changes.

us-east-1

Approach Time Difference
Sequential (requests blocking loop)
49.61s
Baseline
Concurrent (aiohttp + asyncio.gather )
1.56s
31.8Γ— faster

Each request must complete before the next one starts.

chunk 1 ──> request ──> ⏳ wait (~1.5s) ──> response
chunk 2 ──> request ──> ⏳ wait (~1.5s) ──> response
chunk 3 ──> request ──> ⏳ wait (~1.5s) ──> response
...
Total Time β‰ˆ (33 chunks Γ— ~1.5s) β‰ˆ 49.6s

Since network latency dominates the runtime, the event loop sits completely unused.

Requests are dispatched concurrently; total time collapses down to the duration of the slowest single request.

chunk 1  ──> request ──────────────> response
chunk 2  ──> request ──────────────> response
chunk 3  ──> request ──────────────> response
...        (in flight concurrently)
Total Time β‰ˆ slowest single request β‰ˆ 1.56s
php
import requests

def generate_embeddings(texts: list[str]) -> list[list[float]]:
    all_embeddings = []
    for text in texts:
        response = requests.post(url, headers=headers, json={"inputText": text})
        vector = response.json().get("embedding", [])
        all_embeddings.append(vector)
    return all_embeddings
python
import asyncio
import aiohttp

async def fetch_embedding(session: aiohttp.ClientSession, text: str) -> list[float]:
    async with session.post(url, headers=headers, json={"inputText": text}) as res:
        data = await res.json()
        return data.get("embedding", [])

async def generate_embeddings_async(texts: list[str]) -> list[list[float]]:
    async with aiohttp.ClientSession() as session:
        tasks = [fetch_embedding(session, text) for text in texts]
        return await asyncio.gather(*tasks)

Note: If you're using boto3 instead of raw HTTP requests, look at aioboto3, or offload the blocking SDK calls with asyncio.to_thread() to get similar non-blocking behaviour.

Chunks Sequential (est.) Concurrent (est.)
31 49.61s 1.56s
100 ~160s (2.7 min) ~2–3s
500 ~800s (13 min) ~3–5s
1,000 ~1,600s (26 min) ~5–10s

The more chunks you ingest, the more the concurrent approach pays off β€” batch ingestion jobs that took half an hour now finish in seconds.

asyncio.Semaphore

) before you hit them.embedder.py

) removed the embedding stage as a bottleneck in the pipeline.

── more in #artificial-intelligence 4 stories Β· sorted by recency
── more on @aws bedrock 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/31-8x-speedup-by-cha…] indexed:0 read:2min 2026-07-27 Β· β€”