37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
import asyncio
|
|
import httpx
|
|
|
|
with open('my_list.txt', 'r') as file:
|
|
ip_list = [line.strip() for line in file]
|
|
|
|
async def send_request(client, server_ip, rangee, sigma):
|
|
data = {
|
|
"a": rangee[0],
|
|
"b": rangee[1],
|
|
"sigma": sigma
|
|
}
|
|
response = await client.post(f"http://{server_ip}:8000/compute", json=data, timeout=300.0)
|
|
return response.text
|
|
|
|
# Główna funkcja do wysyłania zapytań do wszystkich serwerów równocześnie
|
|
async def main(a_start, b_end, sigma):
|
|
num_chunks = len(ip_list)
|
|
chunk_size = (b_end - a_start + num_chunks) // num_chunks
|
|
ranges = [(a_start + i * chunk_size, min(a_start + (i + 1) * chunk_size - 1, b_end))
|
|
for i in range(num_chunks)]
|
|
async with httpx.AsyncClient() as client:
|
|
tasks = [send_request(client, server, rangee, sigma) for server, rangee in zip(ip_list, ranges)]
|
|
results = await asyncio.gather(*tasks)
|
|
final_result = 0
|
|
for idx, result in enumerate(results):
|
|
final_result += int(result.strip('"'))
|
|
final_result = final_result % 999999937
|
|
print(final_result)
|
|
|
|
# Uruchomienie głównej funkcji
|
|
if __name__ == "__main__":
|
|
sigma = 1220131495
|
|
a = 1
|
|
b = 10000
|
|
asyncio.run(main(a, b, sigma))
|