Add log when response is generated from scratch
This commit is contained in:
6
bench.py
6
bench.py
@@ -14,7 +14,7 @@ async def extract_links(url):
|
|||||||
|
|
||||||
async def benchmark(url):
|
async def benchmark(url):
|
||||||
# This will still block, because subprocess.run is not async
|
# 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/'
|
url = 'http://localhost:9999/http/'
|
||||||
|
|
||||||
@@ -25,7 +25,9 @@ async def main():
|
|||||||
|
|
||||||
print("BENCHMARKING " + link)
|
print("BENCHMARKING " + link)
|
||||||
await benchmark(link)
|
await benchmark(link)
|
||||||
|
async for inl in extract_links(link):
|
||||||
|
print("BENCHMARKING " + inl)
|
||||||
|
await benchmark(inl)
|
||||||
|
|
||||||
# Python 3.7+
|
# Python 3.7+
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.To
|
|||||||
case len(filteredSegments) == 0:
|
case len(filteredSegments) == 0:
|
||||||
output, err = handleListDirectories(w, t)
|
output, err = handleListDirectories(w, t)
|
||||||
case len(filteredSegments) == 1:
|
case len(filteredSegments) == 1:
|
||||||
output, err = handleListTorrents(w, requestPath, t)
|
output, err = handleListTorrents(w, requestPath, t, log)
|
||||||
case len(filteredSegments) == 2:
|
case len(filteredSegments) == 2:
|
||||||
output, err = handleListFiles(w, requestPath, t)
|
output, err = handleListFiles(w, requestPath, t, log)
|
||||||
default:
|
default:
|
||||||
log.Warnf("Request %s %s not found", r.Method, requestPath)
|
log.Warnf("Request %s %s not found", r.Method, requestPath)
|
||||||
http.Error(w, "Not Found", http.StatusNotFound)
|
http.Error(w, "Not Found", http.StatusNotFound)
|
||||||
@@ -68,14 +68,15 @@ func handleListDirectories(w http.ResponseWriter, t *torrent.TorrentManager) (*s
|
|||||||
return &davDoc, nil
|
return &davDoc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleListTorrents(w http.ResponseWriter, requestPath string, t *torrent.TorrentManager) (*string, error) {
|
func handleListTorrents(w http.ResponseWriter, requestPath string, t *torrent.TorrentManager, log *zap.SugaredLogger) (*string, error) {
|
||||||
basePath := path.Base(requestPath)
|
directory := path.Base(requestPath)
|
||||||
_, ok := t.DirectoryMap.Get(basePath)
|
_, ok := t.DirectoryMap.Get(directory)
|
||||||
if !ok {
|
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 := "<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">"
|
davDoc := "<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">"
|
||||||
davDoc += dav.Directory("", "")
|
davDoc += dav.Directory("", "")
|
||||||
directories := t.DirectoryMap.Keys()
|
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))
|
directory := path.Base(path.Dir(requestPath))
|
||||||
torrents, ok := t.DirectoryMap.Get(directory)
|
torrents, ok := t.DirectoryMap.Get(directory)
|
||||||
if !ok {
|
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 {
|
if resp, ok := t.ResponseCache.Get(directory + "/" + accessKey + ".dav"); !ok {
|
||||||
|
log.Debugf("Generating xml for torrent %s", accessKey)
|
||||||
davDoc := "<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">" + dav.BaseDirectory(filepath.Join(directory, tor.AccessKey), tor.LatestAdded)
|
davDoc := "<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">" + dav.BaseDirectory(filepath.Join(directory, tor.AccessKey), tor.LatestAdded)
|
||||||
filenames := tor.SelectedFiles.Keys()
|
filenames := tor.SelectedFiles.Keys()
|
||||||
sort.Strings(filenames)
|
sort.Strings(filenames)
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ func HandleDirectoryListing(w http.ResponseWriter, r *http.Request, t *torrent.T
|
|||||||
case len(filteredSegments) == 1:
|
case len(filteredSegments) == 1:
|
||||||
output, err = handleRoot(t)
|
output, err = handleRoot(t)
|
||||||
case len(filteredSegments) == 2:
|
case len(filteredSegments) == 2:
|
||||||
output, err = handleListOfTorrents(requestPath, t)
|
output, err = handleListOfTorrents(requestPath, t, log)
|
||||||
case len(filteredSegments) == 3:
|
case len(filteredSegments) == 3:
|
||||||
output, err = handleSingleTorrent(requestPath, t)
|
output, err = handleSingleTorrent(requestPath, t, log)
|
||||||
default:
|
default:
|
||||||
log.Warnf("Request %s %s not found", r.Method, requestPath)
|
log.Warnf("Request %s %s not found", r.Method, requestPath)
|
||||||
http.Error(w, "Not Found", http.StatusNotFound)
|
http.Error(w, "Not Found", http.StatusNotFound)
|
||||||
@@ -64,7 +64,7 @@ func handleRoot(t *torrent.TorrentManager) (*string, error) {
|
|||||||
return &htmlDoc, nil
|
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)
|
directory := path.Base(requestPath)
|
||||||
torrents, ok := t.DirectoryMap.Get(directory)
|
torrents, ok := t.DirectoryMap.Get(directory)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -72,6 +72,7 @@ func handleListOfTorrents(requestPath string, t *torrent.TorrentManager) (*strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
if resp, ok := t.ResponseCache.Get(directory + ".html"); !ok {
|
if resp, ok := t.ResponseCache.Get(directory + ".html"); !ok {
|
||||||
|
log.Debugf("Generating html for directory %s", directory)
|
||||||
htmlDoc := "<ol>"
|
htmlDoc := "<ol>"
|
||||||
var allTorrents []*torrent.Torrent
|
var allTorrents []*torrent.Torrent
|
||||||
torrents.IterCb(func(_ string, tor *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))
|
directory := path.Base(path.Dir(requestPath))
|
||||||
torrents, ok := t.DirectoryMap.Get(directory)
|
torrents, ok := t.DirectoryMap.Get(directory)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -106,6 +107,7 @@ func handleSingleTorrent(requestPath string, t *torrent.TorrentManager) (*string
|
|||||||
}
|
}
|
||||||
|
|
||||||
if resp, ok := t.ResponseCache.Get(directory + "/" + accessKey + ".html"); !ok {
|
if resp, ok := t.ResponseCache.Get(directory + "/" + accessKey + ".html"); !ok {
|
||||||
|
log.Debugf("Generating html for torrent %s", accessKey)
|
||||||
htmlDoc := "<ol>"
|
htmlDoc := "<ol>"
|
||||||
filenames := tor.SelectedFiles.Keys()
|
filenames := tor.SelectedFiles.Keys()
|
||||||
sort.Strings(filenames)
|
sort.Strings(filenames)
|
||||||
|
|||||||
Reference in New Issue
Block a user