Update
This commit is contained in:
parent
8b0322cd22
commit
edcfb81f61
@ -3,7 +3,7 @@ from hcloud.images.domain import Image
|
|||||||
from hcloud.server_types.domain import ServerType
|
from hcloud.server_types.domain import ServerType
|
||||||
from hcloud.locations.domain import Location
|
from hcloud.locations.domain import Location
|
||||||
|
|
||||||
servers_no = 2
|
servers_no = 16
|
||||||
|
|
||||||
TOKEN = "V5gkzZ13coCVPKWkQbmbyGPyxDdsTjiubwVtx35jH7mix8A32JqM5CWJtqoLjtFK"
|
TOKEN = "V5gkzZ13coCVPKWkQbmbyGPyxDdsTjiubwVtx35jH7mix8A32JqM5CWJtqoLjtFK"
|
||||||
|
|
||||||
@ -57,4 +57,4 @@ with open('my_list.txt', 'w') as file:
|
|||||||
for item in ip_list:
|
for item in ip_list:
|
||||||
file.write(item + '\n')
|
file.write(item + '\n')
|
||||||
|
|
||||||
print("Finished")
|
print("Finished")
|
||||||
|
38
execute.py
Normal file
38
execute.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
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 + 1) // 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)]
|
||||||
|
# tasks2 = [send_request(client, server, rangee, sigma) for server, rangee in zip(ip_list, ranges[16:32])]
|
||||||
|
# tasks.extend(tasks2)
|
||||||
|
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 = 510104288
|
||||||
|
a = 1
|
||||||
|
b = 7000
|
||||||
|
asyncio.run(main(a, b, sigma))
|
30
main.py
30
main.py
@ -1,3 +1,5 @@
|
|||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -11,19 +13,31 @@ class ComputeInput(BaseModel):
|
|||||||
b: str
|
b: str
|
||||||
sigma: str
|
sigma: str
|
||||||
|
|
||||||
|
def run_compute(a,b,sigma):
|
||||||
@app.post("/compute")
|
|
||||||
async def compute(data: ComputeInput):
|
|
||||||
a = data.a
|
|
||||||
b = data.b
|
|
||||||
sigma = data.sigma
|
|
||||||
|
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
['./computeC', a, b, sigma],
|
['./computeC', str(a), str(b), sigma],
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True
|
text=True
|
||||||
)
|
)
|
||||||
return result.stdout.strip()
|
return result.stdout.strip()
|
||||||
|
|
||||||
|
@app.post("/compute")
|
||||||
|
async def compute(data: ComputeInput):
|
||||||
|
a_start = int(data.a)
|
||||||
|
b_end = int(data.b)
|
||||||
|
sigma = data.sigma
|
||||||
|
|
||||||
|
num_chunks = 8
|
||||||
|
|
||||||
|
chunk_size = (b_end - a_start + 1) // num_chunks
|
||||||
|
ranges = [(a_start + i * chunk_size, min(a_start + (i + 1) * chunk_size - 1, b_end))
|
||||||
|
for i in range(num_chunks)]
|
||||||
|
|
||||||
|
with ThreadPoolExecutor() as executor:
|
||||||
|
futures = [executor.submit(run_compute, a, b, sigma) for a, b in ranges]
|
||||||
|
results = [f.result() for f in futures]
|
||||||
|
|
||||||
|
return sum(results)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||||
|
Loading…
Reference in New Issue
Block a user