An asyncio tcp proxy for network resilience testing
Project description
Toxic Proxy
Toxic Proxy is an asyncio-based TCP proxy designed for network resilience testing. This allows you to simulate network conditions like latency, bandwidth limitations, and other issues to test how your application behaves under different scenarios. Whether you're working with microservices or just need to test your network reliability, Toxic Proxy provides a flexible way to introduce network anomalies for better resilience testing.
Features
- Simulate network latency
- Limit bandwidth
- Easy to integrate with Python applications
- Uses asyncio for high performance
Installation
Install Toxic Proxy using pip.
pip install --upgrade toxic_proxy
Quick Start
Using with Cassandra
Here's an example that shows how to use Toxic Proxy with a Cassandra cluster.
import asyncio
from aiocassandra import aiosession
from cassandra.cluster import Cluster
from toxic_proxy import toxic_proxy
# Create a proxy with latency
proxy = toxic_proxy(
destination=('<cassandra-ip>', 9042),
latency=5,
port=9043
)
# Connect to Cassandra through the proxy
cluster = Cluster(['0.0.0.0:9043'])
session = cluster.connect()
# ... your code here ...
Simplified Example
This example demonstrates a simple use case to limit bandwidth when connecting to google.com.
import asyncio
from toxic_proxy import toxic_proxy
# Create a proxy with bandwidth limit
proxy = toxic_proxy(
destination=('google.com', 80),
bandwidth_rate_kb=0.5,
port=8888
)
loop = asyncio.get_event_loop()
server = loop.run_until_complete(proxy)
print(f'Serving on {server.sockets[0].getsockname()}')
try:
loop.run_forever()
except KeyboardInterrupt:
pass
# Close the server
server.close()
loop.run_until_complete(server.wait_closed())
loop.close()
Testing
To test, you can use curl to make a request through the proxy.
curl -v 0.0.0.0:8888
Contributing
We welcome contributions! If you find a bug or have a feature request, please open an issue. If you want to contribute code, feel free to open a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file toxic_proxy-0.1.0.tar.gz
.
File metadata
- Download URL: toxic_proxy-0.1.0.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.9.16 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fb07bc3fa734c87441f0c4883462129395a08a576ec75cfc08d8bb0a8287e31 |
|
MD5 | e12a1c48683ce37cd5ca2205f60b670c |
|
BLAKE2b-256 | 6ff04c69fd0122871ca946550bfa50b6e49af010d93ee46c39247fe2540c8747 |