diff --git a/bench.py b/bench.py new file mode 100644 index 0000000..c8bc227 --- /dev/null +++ b/bench.py @@ -0,0 +1,30 @@ +import aiohttp +import asyncio +from bs4 import BeautifulSoup +from urllib.parse import urljoin +import subprocess + +async def extract_links(url): + async with aiohttp.ClientSession() as session: + async with session.get(url) as response: + soup = BeautifulSoup(await response.text(), 'html.parser') + for link in soup.find_all('a'): + yield urljoin(url, link.get('href')) + +async def benchmark(url): + # This will still block, because subprocess.run is not async + subprocess.run(['hey', '-n', '100', '-c', '10', url]) + +url = 'http://zen.box:9999/http/' + +async def main(): + i = 1 + async for link in extract_links(url): + if i > 50: + break + await benchmark(link) + await benchmark(link.replace('/http/', '/')) + i += 1 + +# Python 3.7+ +asyncio.run(main()) diff --git a/cmd/zurg/main.go b/cmd/zurg/main.go index dd8c169..983beba 100644 --- a/cmd/zurg/main.go +++ b/cmd/zurg/main.go @@ -15,6 +15,8 @@ import ( zurghttp "github.com/debridmediamanager.com/zurg/pkg/http" "github.com/debridmediamanager.com/zurg/pkg/logutil" "github.com/debridmediamanager.com/zurg/pkg/realdebrid" + + _ "net/http/pprof" ) func main() { @@ -55,6 +57,10 @@ func main() { downloadClient := zurghttp.NewHTTPClient(config.GetToken(), config.GetRetriesUntilFailed(), 0, config, log.Named("dlclient")) getfile := universal.NewGetFile(downloadClient) + go func() { + http.ListenAndServe("[::]:6060", nil) + }() + mux := http.NewServeMux() net.Router(mux, getfile, config, torrentMgr, log.Named("net")) diff --git a/internal/dav/listing.go b/internal/dav/listing.go index 154a0de..fb7158b 100644 --- a/internal/dav/listing.go +++ b/internal/dav/listing.go @@ -72,20 +72,10 @@ func handleListTorrents(w http.ResponseWriter, requestPath string, t *torrent.To // initial response is the directory itself fmt.Fprint(w, dav.BaseDirectory(basePath, "")) - var allTorrents []torrent.Torrent - torrents.IterCb(func(key string, tor *torrent.Torrent) { - if tor.AllInProgress() { - return - } - copy := *tor - copy.AccessKey = key - allTorrents = append(allTorrents, copy) - }) - sort.Slice(allTorrents, func(i, j int) bool { - return allTorrents[i].AccessKey < allTorrents[j].AccessKey - }) - - for _, tor := range allTorrents { + allTorrents := torrents.Keys() + sort.Strings(allTorrents) + for _, accessKey := range allTorrents { + tor, _ := torrents.Get(accessKey) fmt.Fprint(w, dav.Directory(tor.AccessKey, tor.LatestAdded)) } diff --git a/internal/http/listing.go b/internal/http/listing.go index bcc6158..22feaf1 100644 --- a/internal/http/listing.go +++ b/internal/http/listing.go @@ -73,21 +73,10 @@ func handleListOfTorrents(requestPath string, t *torrent.TorrentManager) (*strin htmlDoc := "