Skip to content

Remove performance config, hardcode maximum throughput values#59

Merged
karilaa-dev merged 5 commits intomainfrom
dev
Jan 15, 2026
Merged

Remove performance config, hardcode maximum throughput values#59
karilaa-dev merged 5 commits intomainfrom
dev

Conversation

@karilaa-dev
Copy link
Owner

@karilaa-dev karilaa-dev commented Jan 15, 2026

User description

Summary

  • Remove most performance-related environment variables and hardcode values optimized for maximum resource usage
  • ThreadPoolExecutor: 500 workers (vs default 32)
  • aiohttp connections: unlimited (limit=0)
  • curl_cffi pool: 10000 max_clients
  • Image downloads: no concurrency limit (removed semaphore)
  • Keep only 3 user-configurable limits: MAX_USER_QUEUE_SIZE, STREAMING_DURATION_THRESHOLD, MAX_VIDEO_DURATION

Test plan

  • Verify bot starts without errors
  • Test video download functionality
  • Test slideshow download with multiple images
  • Verify queue limiting works when MAX_USER_QUEUE_SIZE > 0

PR Type

Enhancement


Description

  • Remove performance config, hardcode values

  • ThreadPoolExecutor: 500 workers, aiohttp: unlimited

  • curl_cffi: 10000, images: unlimited

  • Keep 3 user-configurable limits


Diagram Walkthrough

flowchart LR
  A["Remove Performance Config"] --> B["Hardcode Maximum Values"]
  B --> C["ThreadPoolExecutor: 500 workers"]
  B --> D["aiohttp: unlimited connections"]
  B --> E["curl_cffi: 10000 max_clients"]
  B --> F["Image downloads: no limit"]
  G["Keep User Limits"] --> H["MAX_USER_QUEUE_SIZE"]
  G --> I["STREAMING_DURATION_THRESHOLD"]
  G --> J["MAX_VIDEO_DURATION"]
Loading

File Walkthrough

Relevant files
Configuration changes
1 files
config.py
Remove performance config fields                                                 
+4/-18   
Enhancement
6 files
get_music.py
Remove aiohttp pool parameters                                                     
+1/-3     
get_video.py
Remove aiohttp pool parameters                                                     
+12/-12 
main.py
Remove executor size configuration                                             
+0/-9     
queue_manager.py
Update queue limit check logic                                                     
+1/-1     
video_types.py
Remove image download concurrency limit                                   
+3/-15   
client.py
Hardcode performance values                                                           
+20/-62 
Documentation
1 files
.env.example
Remove performance env variables                                                 
+8/-19   

Simplify configuration by removing most performance-related env vars
and hardcoding values optimized for maximum resource usage:

- ThreadPoolExecutor: 500 workers (vs default 32)
- aiohttp connections: unlimited (limit=0)
- curl_cffi pool: 10000 max_clients
- Image downloads: no concurrency limit (removed semaphore)

Keep only 3 user-configurable limits via env vars:
- MAX_USER_QUEUE_SIZE (default 0 = no limit)
- STREAMING_DURATION_THRESHOLD (default 300s)
- MAX_VIDEO_DURATION (default 0 = no limit)
@zam-review
Copy link

zam-review bot commented Jan 15, 2026

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Resource Exhaustion Risk

Hardcoded high values for ThreadPoolExecutor (500 workers) and curl_cffi pool (10000 max_clients) without system resource validation could lead to memory exhaustion, file descriptor limits, or system instability on resource-constrained environments (e.g., small VPS or containers). Consider adding system resource checks or making these values configurable with sensible defaults.

_executor: Optional[ThreadPoolExecutor] = None
_executor_lock = threading.Lock()
_executor_size: int = 500  # High value for maximum throughput
Unlimited Connection Limits

Setting aiohttp connector limits to 0 (unlimited) for both total and per-host connections removes all safeguards against connection storms. This could overwhelm the system or trigger rate limiting from TikTok's servers. Consider implementing a reasonable upper bound or adding circuit breaker patterns.

cls._aiohttp_connector = TCPConnector(
    limit=0,  # Unlimited connections
    limit_per_host=0,  # Unlimited per-host connections
Unbounded Image Downloads

Removing the semaphore for image downloads means all slideshow images are downloaded simultaneously. For slideshows with many images (e.g., 50+), this could cause network congestion, memory spikes, or timeouts. Consider adding a configurable upper limit or implementing adaptive concurrency based on system load.

return await asyncio.gather(
    *[client.download_image(url, video_info) for url in image_urls],

@zam-review
Copy link

zam-review bot commented Jan 15, 2026

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Limit unlimited connection pools

Setting unlimited connections (limit=0) can exhaust file descriptors and cause
system instability. Use reasonable limits like 1000 total and 100 per host to
balance throughput with resource safety.

tiktok_api/client.py [317-322]

 cls._aiohttp_connector = TCPConnector(
-    limit=0,  # Unlimited connections
-    limit_per_host=0,  # Unlimited per-host connections
+    limit=1000,  # High but safe connection limit
+    limit_per_host=100,  # Prevent overwhelming single host
     ttl_dns_cache=300,
     enable_cleanup_closed=True,
     force_close=False,  # Keep connections alive for reuse
 )
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies that limit=0 can be risky, but the PR explicitly removes configurable limits in favor of unlimited connections to maximize throughput. While the concern is valid, it contradicts the PR's design intent of removing performance configuration complexity.

Low
Reduce excessive pool size

A pool size of 10000 is excessively high and can cause memory issues or resource
exhaustion. Reduce to a more reasonable value like 500-1000 that still provides high
throughput without risking system stability.

tiktok_api/client.py [269]

-pool_size = 10000  # High value for maximum throughput
+pool_size = 500  # High value for maximum throughput
Suggestion importance[1-10]: 5

__

Why: While 10000 is high, the PR intentionally sets a fixed high value to eliminate configuration complexity. The suggestion contradicts the PR's approach of hardcoding high-performance defaults instead of making them configurable.

Low

@karilaa-dev karilaa-dev merged commit be1fd21 into main Jan 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant