Glossary
Concurrency: doing many requests at once without tipping over
Concurrency is the number of requests or tasks your program keeps in flight at the same moment, and choosing it well decides both speed and how often you get blocked.
Concurrency versus parallelism
Concurrency means many operations are in progress at once; parallelism means they literally execute at the same instant on different CPU cores. A scraper spends most of its time waiting on the network, so it benefits from concurrency even on one core: while one request waits for a reply, the program sends others. That is why a single async process can keep hundreds of connections open (see multi-threaded scraping for the models).
Limits that matter
A global limit alone is not enough. Think in layers:
- Per target host. The number that decides whether a site starts showing challenges or 429 responses. Keep it modest, often a handful of connections.
- Per proxy or IP. Many requests from one address look like one very fast visitor.
- Global. Bounded by your memory, file descriptors and bandwidth.
- Per external API. Every service you call has its own rules. GateSolver allows 600 requests per minute per API key and places no cap on how many tasks run at the same time.
Semaphores as the basic tool
A semaphore is a counter that lets N callers through and makes the rest wait. One semaphore per host is a simple and effective pattern.
import asyncio
from collections import defaultdict
host_gate = defaultdict(lambda: asyncio.Semaphore(4))
async def fetch(client, url, host):
async with host_gate[host]:
reply = await client.get(url, timeout=30)
return reply.status_code, reply.text
Backpressure
Backpressure means a slow stage pushes back on a fast one. If your parser or database writer cannot keep up, an unbounded producer fills memory with pending results. Use bounded queues between stages: when the queue is full, the producer waits. The same idea applies to challenge solving. If many pages hit a CAPTCHA at once, you can create many tasks in parallel, but your polling should be spaced (every 3 seconds for token tasks, every second for image tasks) so the polling itself does not eat the request budget.
Counting your API budget
Each solve costs at least two kinds of calls: one createTask and several getTaskResult polls. With a 3 second interval and a token that takes around ten seconds, a task needs about four or five calls in total. Divide your per minute allowance by that figure to estimate how many solves per minute one key can drive, and keep some headroom for balance checks. If you see ERROR_RATE_LIMIT, slow the pollers first.
Picking a number
Start low, measure, then raise. Track success rate, median latency and how often you see challenge pages per host. When latency climbs or challenges become frequent, you have passed the point where more concurrency helps. A well tuned crawler is often slower per host than you expect and faster overall, because it spreads work across many hosts instead of hammering one. Pair this with a request queue that hands out work by host, and with backoff when a host pushes back.
Common questions
How many concurrent requests should I send to one site?
Start with two to five and increase only while response times and challenge frequency stay flat. Each site tolerates a different level.
Does GateSolver limit how many tasks I run at once?
No. There is no cap on concurrent tasks; the limit is 600 API requests per minute per key, which includes polling calls.
What is backpressure in a scraper?
It is a slower stage forcing faster stages to wait, usually through bounded queues, so memory does not fill with unprocessed work.
Is async better than threads for concurrency?
For network bound scraping, async usually handles more open connections with less memory. Threads are simpler when libraries are blocking.
Why do more parallel requests make me slower?
Past a point the site starts throttling or challenging you, and retries cost more time than the extra parallelism saves.
Keep reading
- Multi-threaded scrapingThreads, async event loops and worker processes compared for scrapers, with the workload each one suits best.
- Rate limitingCaps on requests per IP, key or session, the 429 response that enforces them, and the limit GateSolver applies to its own API.
- Request queueThe list of URLs a crawler still has to visit, with retries, priorities and deduplication built into how it is stored.
- API docscreateTask, getTaskResult, getBalance, error codes and the in.php format.