diff --git a/bench.py b/bench.py index 2156f4e..e324095 100644 --- a/bench.py +++ b/bench.py @@ -14,7 +14,7 @@ async def extract_links(url): async def benchmark(url): # This will still block, because subprocess.run is not async - subprocess.run(['hey', '-n', '100000', '-c', '100', url]) + subprocess.run(['hey', '-n', '10000', '-c', '50', url]) url = 'http://localhost:9999/http/' @@ -25,7 +25,9 @@ async def main(): print("BENCHMARKING " + link) await benchmark(link) - + async for inl in extract_links(link): + print("BENCHMARKING " + inl) + await benchmark(inl) # Python 3.7+ asyncio.run(main()) diff --git a/internal/dav/listing.go b/internal/dav/listing.go index 7ba4830..ae3f660 100644 --- a/internal/dav/listing.go +++ b/internal/dav/listing.go @@ -24,9 +24,9 @@ func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.To case len(filteredSegments) == 0: output, err = handleListDirectories(w, t) case len(filteredSegments) == 1: - output, err = handleListTorrents(w, requestPath, t) + output, err = handleListTorrents(w, requestPath, t, log) case len(filteredSegments) == 2: - output, err = handleListFiles(w, requestPath, t) + output, err = handleListFiles(w, requestPath, t, log) default: log.Warnf("Request %s %s not found", r.Method, requestPath) http.Error(w, "Not Found", http.StatusNotFound) @@ -68,14 +68,15 @@ func handleListDirectories(w http.ResponseWriter, t *torrent.TorrentManager) (*s return &davDoc, nil } -func handleListTorrents(w http.ResponseWriter, requestPath string, t *torrent.TorrentManager) (*string, error) { - basePath := path.Base(requestPath) - _, ok := t.DirectoryMap.Get(basePath) +func handleListTorrents(w http.ResponseWriter, requestPath string, t *torrent.TorrentManager, log *zap.SugaredLogger) (*string, error) { + directory := path.Base(requestPath) + _, ok := t.DirectoryMap.Get(directory) if !ok { - return nil, fmt.Errorf("cannot find directory %s", basePath) + return nil, fmt.Errorf("cannot find directory %s", directory) } - if resp, ok := t.ResponseCache.Get(basePath + ".dav"); !ok { + if resp, ok := t.ResponseCache.Get(directory + ".dav"); !ok { + log.Debugf("Generating xml for directory %s", directory) davDoc := "" davDoc += dav.Directory("", "") directories := t.DirectoryMap.Keys() @@ -91,7 +92,7 @@ func handleListTorrents(w http.ResponseWriter, requestPath string, t *torrent.To } } -func handleListFiles(w http.ResponseWriter, requestPath string, t *torrent.TorrentManager) (*string, error) { +func handleListFiles(w http.ResponseWriter, requestPath string, t *torrent.TorrentManager, log *zap.SugaredLogger) (*string, error) { directory := path.Base(path.Dir(requestPath)) torrents, ok := t.DirectoryMap.Get(directory) if !ok { @@ -104,6 +105,7 @@ func handleListFiles(w http.ResponseWriter, requestPath string, t *torrent.Torre } if resp, ok := t.ResponseCache.Get(directory + "/" + accessKey + ".dav"); !ok { + log.Debugf("Generating xml for torrent %s", accessKey) davDoc := "" + dav.BaseDirectory(filepath.Join(directory, tor.AccessKey), tor.LatestAdded) filenames := tor.SelectedFiles.Keys() sort.Strings(filenames) diff --git a/internal/http/listing.go b/internal/http/listing.go index 6eb5d0f..adfde6d 100644 --- a/internal/http/listing.go +++ b/internal/http/listing.go @@ -24,9 +24,9 @@ func HandleDirectoryListing(w http.ResponseWriter, r *http.Request, t *torrent.T case len(filteredSegments) == 1: output, err = handleRoot(t) case len(filteredSegments) == 2: - output, err = handleListOfTorrents(requestPath, t) + output, err = handleListOfTorrents(requestPath, t, log) case len(filteredSegments) == 3: - output, err = handleSingleTorrent(requestPath, t) + output, err = handleSingleTorrent(requestPath, t, log) default: log.Warnf("Request %s %s not found", r.Method, requestPath) http.Error(w, "Not Found", http.StatusNotFound) @@ -64,7 +64,7 @@ func handleRoot(t *torrent.TorrentManager) (*string, error) { return &htmlDoc, nil } -func handleListOfTorrents(requestPath string, t *torrent.TorrentManager) (*string, error) { +func handleListOfTorrents(requestPath string, t *torrent.TorrentManager, log *zap.SugaredLogger) (*string, error) { directory := path.Base(requestPath) torrents, ok := t.DirectoryMap.Get(directory) if !ok { @@ -72,6 +72,7 @@ func handleListOfTorrents(requestPath string, t *torrent.TorrentManager) (*strin } if resp, ok := t.ResponseCache.Get(directory + ".html"); !ok { + log.Debugf("Generating html for directory %s", directory) htmlDoc := "
    " var allTorrents []*torrent.Torrent torrents.IterCb(func(_ string, tor *torrent.Torrent) { @@ -93,7 +94,7 @@ func handleListOfTorrents(requestPath string, t *torrent.TorrentManager) (*strin } } -func handleSingleTorrent(requestPath string, t *torrent.TorrentManager) (*string, error) { +func handleSingleTorrent(requestPath string, t *torrent.TorrentManager, log *zap.SugaredLogger) (*string, error) { directory := path.Base(path.Dir(requestPath)) torrents, ok := t.DirectoryMap.Get(directory) if !ok { @@ -106,6 +107,7 @@ func handleSingleTorrent(requestPath string, t *torrent.TorrentManager) (*string } if resp, ok := t.ResponseCache.Get(directory + "/" + accessKey + ".html"); !ok { + log.Debugf("Generating html for torrent %s", accessKey) htmlDoc := "
      " filenames := tor.SelectedFiles.Keys() sort.Strings(filenames)