Add debug symbols

This commit is contained in:
Ben Sarmiento
2023-11-28 21:38:48 +01:00
parent ee766dba6a
commit 606a19eca5
4 changed files with 44 additions and 29 deletions

30
bench.py Normal file
View File

@@ -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())

View File

@@ -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"))

View File

@@ -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))
}

View File

@@ -73,21 +73,10 @@ func handleListOfTorrents(requestPath string, t *torrent.TorrentManager) (*strin
htmlDoc := "<ol>"
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 {
htmlDoc = htmlDoc + fmt.Sprintf("<li><a href=\"%s/\">%s</a></li>", filepath.Join(requestPath, url.PathEscape(tor.AccessKey)), tor.AccessKey)
allTorrents := torrents.Keys()
sort.Strings(allTorrents)
for _, accessKey := range allTorrents {
htmlDoc = htmlDoc + fmt.Sprintf("<li><a href=\"%s/\">%s</a></li>", filepath.Join(requestPath, url.PathEscape(accessKey)), accessKey)
}
return &htmlDoc, nil
}