You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You need to pass a base-url parameter like so: GITHUB_TOKEN= lychee index.html -pv --base-url "http://example.com"
Would that cover your use-case?
We could add support for checking local files as well if that helps.
Ah so it is always going to do network I/O? Ok, that clarifies that then. I just assumed it would do local file checking because the input is already a local file (i.e. work closer to how liche works). I think I'll just run a local http server for CI like I did with the others then and pass an URL.
As for usecases: I am only doing benchmark comparisons around a bunch of link checkers. My usecase is checking internal links of the html generated by a static site generator, and that as part of CI, but I wrote my own link checker for that. Whose small featureset, incredibly, seems to be the exact inverse to lychee's. Just shows that link checker is an overloaded term.
Two pieces of feedback, but keep in mind that those don't come from a "real user":
Right now GITHUB_TOKEN is a required envvar, but readme does not call that out. I don't have github links to check though, so I think it should be optional
would be good to document --base-url in readme as required for relative urls (or perhaps warn in-app that there are relative links that could not be resolved because --base-url is not set)
Right now GITHUB_TOKEN is a required envvar, but readme does not call that out. I don't have github links to check though, so I think it should be optional
would be good to document --base-url in readme as required for relative urls (or perhaps warn in-app that there are relative links that could not be resolved because --base-url is not set)
True. Come to think of it, checking relative URLs in case a file name is given might be the default. Wonder what @whizsid and @pawroman think about it.
Liche does this thing where it aborts link checking entirely when it encounters a host-relative URL while parsing a local file and base-url is not set. I have to write this for anything to work:
which is kind of silly, but it does allow those arguments to diverge, and still lets liche resolve /foo/bar hrefs (host-relative but path-absolute) correctly:
(The -x prevents liche from checking external links. I personally want this because above all the check should not be flaky, as it runs in CI. It's another kind of usecase that I find most linkcheckers don't really cater well to, or make ergonomic)
Also I just realized that lychee does not support recursive traversal of links at all, or am I wrong? Had to combine find, xargs and lychee in godforsaken ways but obviously that does not perform very well...
Nope, recursion is still on the todo list (see readme). My idea was to use channels for handling in-flight checks; do you use the same in hyperlink?
I do like your other ideas.
hyperlink can only crawl directories and resolve relative/internal links (no http support at all), as such it walks through the entire directory first using walkdir/jwalk then parallelizes parsing all found files with Rayon. No graph traversal over hrefs, just directory walking.
I honestly don't know enough about post-futures-0.1 async but I suppose you could do something with the mpsc one? So you have a single consumer that is in charge of spawning new fetch tasks and deduplicating fetch tasks. And each fetch task gets a producer.
I honestly don't know enough about post-futures-0.1 async but I suppose you could do something with the mpsc one? So you have a single consumer that is in charge of spawning new fetch tasks and deduplicating fetch tasks. And each fetch task gets a producer.
Precisely. Would love a comparison between async and rayon for that use-case. My guess is that perf would be similar while async would use slightly less resources when dealing with many tasks. Then again threads are super optimized as well on modern hardware so there might be no difference after all.
I did see that liche, which uses goroutines, is slightly faster than hyperlink on folders with >1 mio files, but because liche spawned over 200 threads on my mac (while hyperlink spawned 12) I also assumed it effectively did use a thread pool, not actual async syscalls for file I/O.
I did pick basic threading over tokio because I thought outside of networking (I didn't care about HTTP at all) it would not make a difference, and also because it definetly seems I would be able to reuse buffers much more efficiently.
I just googled some stuff and apparently there are async syscalls for reading files on macos.
Anyway, it would be a massive pain to support external links in hyperlink so I probably painted myself into a corner already.
I am disabling so many features of those other link checkers that I am kind of comparing apples with oranges. Particularly lychee looks like it would generally just serve very different usecases.
For link checkers which only support HTTP I need to make sure that the link checker is not bottlenecked on the local http server that serves up what would be directly accessed by hyperlink. Figuring that out is not easy without distorting results further. Also, again, apples vs oranges.
It is good if we can provide a file checker. Because most of users using link checkers for CI/CD actions. It will fail when they are adding a new relative URL. Because this relative URL is not already exist on provided site at the time. I would like to work on this.
Reacted by Shon, Brennan Kinney, Elena Neroslavskaya and MichaIng
We could check if a file exists if base-url is not set. Additionally I'm wondering if we should only check for a file if the relative link also came from a file. My reasoning is that it could cause some false-positives if a file exists that just happens to have the same name as a relative link on a website. Might be an edge-case, though and make things unnecessarily complex...
Would love to get some opinions on this before we start.
The now deprecated liche had the most reasonable implementation for "local" links, IMO:
Relative local links (not starting with a slash) simply check for local files relative to the originating document, just as it would work on the "published" document, assuming that all local targets are present when the originating document is. This is true for 99% of cases and otherwise it makes sense for the developer to set links with full URL, if the targets are not part of the website/document repository that is to be checked.
Absolute local links (leading slash) require the base dir option to define the document root, which can be an external URL as well as a local directory path. So I was able to do liche -d build -r build/docs to check all local links, where the website is built into the build/docs directory and will be reached at https://example.org/docs finally.
Of course it makes sense to only check file existence in case of relative local URLs or when a directory path is given for the base dir/url.
The ability to check for local files is quite important, as even if the website that you want to test is available via HTTP(S), it's internal structure may have changed and one needs to be able to check whether all internal relative links are intact.
Reacted by Matthias Endler, Eric Myhre, Paweł Romanowski, Kevin van Rijn, Shon, Sebastian Spier and Brennan Kinney
Will test in detail next week, hopefully. I left a comment on the pr, it seems to me lychee-on-fs is still built for different usecases than what I need.
progressbar is really slowing things down. by disabling it using a pipe I get down from 3 minutes to 32 seconds on sentry-docs, which is roughly on-par with liche. hyperlink is still doing that site in 2 secs
besides progressbar there's some room for optimization, I see lychee maxes out all cores traversing the filesystem upfront, then does not manage to saturate CPU at all anymore when it begins to show the progressbar and tries to advance
the problem with anchors not being stripped occurs for me as well
other than that lgtm
full command I ran in sentry-docs after following their setup:
yarn
yarn build
cd public/
time ~/projects/lychee/target/release/lychee --offline -b . '**/*.html' |& tee log
progressbar is really slowing things down. by disabling it using a pipe I get down from 3 minutes to 32 seconds on sentry-docs, which is roughly on-par with liche. hyperlink is still doing that site in 2 secs
Wow. There are similar reports here: console-rs/indicatif#170
Good job on making hyperlink so fast! 😃
I see lychee maxes out all cores traversing the filesystem upfront, then does not manage to saturate CPU at all anymore when it begins to show the progressbar and tries to advance
This is true. The problem is the current collector implementation. It pushes all file contents into a channel before checking. That's extremely wasteful. I think just using streams would be the better alternative. This should be tackled once basic file support gets merged. @lebensterben we talked about that before. I could need your help on this. 😅
the problem with anchors not being stripped occurs for me as well
Yup, that was an oversight. It should be fixed now.
@untitaker, tried to reproduce your sentry use-case:
time lychee --offline -b . '**/*.html' --no-progress --verbose
Error: Too many open files (os error 24)
This is clearly not working and we'll need to move to a lazy link collection approach.
It won't happen on the first iteration, but there is obviously some refactoring work to do before file support is suitable for bigger sites. 😞
True.
In the following snippet we return the Result<Vec<InputContent>>, which is fine when we deal with a few files, but when it calls glob_contents with a pattern like **/*.html on a big directory it will run out of file handles because it eagerly reads all those files.
It indirectly affects local file support if there a lot of files to handle (as in the sentry example).
The better approach is to lazily evaluate each file e.g. by using a stream. I will play around with streams a bit to see if I can build something fast and efficient. If anyone wants to help me with that, feel free to create a test repo, a pull request or we can even pair program on this together (UTC+2 timezone).
local disk IO is not CPU bound. we'd expect most files are processed below 10s (the default timeout before tokio steal a thread), so using asynchronous here isn't really helpful either.
and suppose tokio really does steal from a thread, that only adds unnecessary cost of context switching.
it's relatively cheap for us to factor out the network IO from other parts, and use tokio and crossbeam, respectively, for local and network IO.
roughly speaking,
CLI args and/or config file parsing is synchrnonous and single-thread in nature.
walking directories according to glob pattern, and grabbing URLs from files are synchronous but can benefit from parallelism (suppose that it's not running on crappy hard disk)
the "spawner" of worker pool is the boundary of sync and async. this is actually the part we should spend most effort on.
workers are async. but there's not much room to work on. after all, when a HTTP request is sent and before we received anything from server, it's out of our control.
For some reason I only see your comments now. What you say all makes sense and we should go forward with that.
As you mentioned, we can take a lesson from ripgrep's book. Since ripgrep and lychee and many others seem to have the same requirements for fast filesystem traversal, I wonder if there should be a separate crate, which can wrap that functionality behind a nice, performant interface. But yeah, rayon sounds like a good idea and spawn_blocking sounds like a great combination.
Jwalk already implements walkdir on rayon, I've found it to be on-par with custom rayon or ripgrep. That said if you want to honor gitignore etc maybe you want to look at ripgrep. I just didn't find their code particularly reusable (relatively speaking)
jwalk looks great. We should use that if the input is a directory. Would be nice to add glob support to it, but it might be out of scope for the crate. 🤷
ripgrep probably covers more edge-cases, but as you said it's not very reusable as a library, so jwalk is probably our best option.
Activity
mre commentedon Oct 25, 2020
You need to pass a
base-urlparameter like so:GITHUB_TOKEN= lychee index.html -pv --base-url "http://example.com"Would that cover your use-case?
We could add support for checking local files as well if that helps.
untitaker commentedon Oct 25, 2020
Ah so it is always going to do network I/O? Ok, that clarifies that then. I just assumed it would do local file checking because the input is already a local file (i.e. work closer to how liche works). I think I'll just run a local http server for CI like I did with the others then and pass an URL.
As for usecases: I am only doing benchmark comparisons around a bunch of link checkers. My usecase is checking internal links of the html generated by a static site generator, and that as part of CI, but I wrote my own link checker for that. Whose small featureset, incredibly, seems to be the exact inverse to lychee's. Just shows that link checker is an overloaded term.
Two pieces of feedback, but keep in mind that those don't come from a "real user":
--base-urlin readme as required for relative urls (or perhaps warn in-app that there are relative links that could not be resolved because--base-urlis not set)mre commentedon Oct 25, 2020
Good points!
This is tackled by @pawroman in #22. 🎉
True. Come to think of it, checking relative URLs in case a file name is given might be the default. Wonder what @whizsid and @pawroman think about it.
untitaker commentedon Oct 25, 2020
Liche does this thing where it aborts link checking entirely when it encounters a host-relative URL while parsing a local file and base-url is not set. I have to write this for anything to work:
which is kind of silly, but it does allow those arguments to diverge, and still lets liche resolve
/foo/barhrefs (host-relative but path-absolute) correctly:I think a hybrid where --document-root defaults to the parent path of the file given would be good, so I can write both:
(The
-xprevents liche from checking external links. I personally want this because above all the check should not be flaky, as it runs in CI. It's another kind of usecase that I find most linkcheckers don't really cater well to, or make ergonomic)untitaker commentedon Oct 25, 2020
Also I just realized that lychee does not support recursive traversal of links at all, or am I wrong? Had to combine
find,xargsandlycheein godforsaken ways but obviously that does not perform very well...mre commentedon Oct 25, 2020
Nope, recursion is still on the todo list (see readme). My idea was to use channels for handling in-flight checks; do you use the same in hyperlink?
I do like your other ideas.
untitaker commentedon Oct 25, 2020
hyperlink can only crawl directories and resolve relative/internal links (no http support at all), as such it walks through the entire directory first using walkdir/jwalk then parallelizes parsing all found files with Rayon. No graph traversal over hrefs, just directory walking.
I honestly don't know enough about post-futures-0.1 async but I suppose you could do something with the mpsc one? So you have a single consumer that is in charge of spawning new fetch tasks and deduplicating fetch tasks. And each fetch task gets a producer.
mre commentedon Oct 25, 2020
Precisely. Would love a comparison between async and rayon for that use-case. My guess is that perf would be similar while async would use slightly less resources when dealing with many tasks. Then again threads are super optimized as well on modern hardware so there might be no difference after all.
untitaker commentedon Oct 25, 2020
I did see that liche, which uses goroutines, is slightly faster than hyperlink on folders with >1 mio files, but because liche spawned over 200 threads on my mac (while hyperlink spawned 12) I also assumed it effectively did use a thread pool, not actual async syscalls for file I/O.
I did pick basic threading over tokio because I thought outside of networking (I didn't care about HTTP at all) it would not make a difference, and also because it definetly seems I would be able to reuse buffers much more efficiently.
I just googled some stuff and apparently there are async syscalls for reading files on macos.
Anyway, it would be a massive pain to support external links in hyperlink so I probably painted myself into a corner already.
untitaker commentedon Oct 25, 2020
I am planning to do semi-serious benchmarks across a bunch of link checkers. I haven't figured out how yet.
Right now my approach to informal testing was to set up a random link checker, disable most of features such that the featureset roughly matches the few things hyperlink can do, then compare them on https://github.com/getsentry/sentry-docs and some synthetic stuff. Unfortunately there's two problems with this:
whizsid commentedon Oct 28, 2020
It is good if we can provide a file checker. Because most of users using link checkers for CI/CD actions. It will fail when they are adding a new relative URL. Because this relative URL is not already exist on provided site at the time. I would like to work on this.
mre commentedon Oct 28, 2020
Sure @whizsid, go for it.
We could check if a file exists if
base-urlis not set. Additionally I'm wondering if we should only check for a file if the relative link also came from a file. My reasoning is that it could cause some false-positives if a file exists that just happens to have the same name as a relative link on a website. Might be an edge-case, though and make things unnecessarily complex...Would love to get some opinions on this before we start.
mre commentedon Nov 25, 2020
@whizsid are you still working on this? Let me know if you need any support.
MichaIng commentedon Dec 19, 2020
The now deprecated liche had the most reasonable implementation for "local" links, IMO:
liche -d build -r build/docsto check all local links, where the website is built into thebuild/docsdirectory and will be reached athttps://example.org/docsfinally.The ability to check for local files is quite important, as even if the website that you want to test is available via HTTP(S), it's internal structure may have changed and one needs to be able to check whether all internal relative links are intact.
9 remaining items
mre commentedon Sep 4, 2021
@untitaker can you help me with testing #262?
Of course, if anyone else has some time, feedback is very welcome.
untitaker commentedon Sep 4, 2021
untitaker commentedon Sep 6, 2021
Ok, everything I encountered:
other than that lgtm
full command I ran in sentry-docs after following their setup:
mre commentedon Sep 6, 2021
Wow. There are similar reports here: console-rs/indicatif#170
Good job on making hyperlink so fast! 😃
This is true. The problem is the current collector implementation. It pushes all file contents into a channel before checking. That's extremely wasteful. I think just using streams would be the better alternative. This should be tackled once basic file support gets merged. @lebensterben we talked about that before. I could need your help on this. 😅
Yup, that was an oversight. It should be fixed now.
mre commentedon Sep 6, 2021
@untitaker, tried to reproduce your sentry use-case:
This is clearly not working and we'll need to move to a lazy link collection approach.
It won't happen on the first iteration, but there is obviously some refactoring work to do before file support is suitable for bigger sites. 😞
MichaIng commentedon Sep 7, 2021
@mre
This is not related to the local files support itself, is it?
mre commentedon Sep 7, 2021
True.
In the following snippet we return the
Result<Vec<InputContent>>, which is fine when we deal with a few files, but when it callsglob_contentswith a pattern like**/*.htmlon a big directory it will run out of file handles because it eagerly reads all those files.lychee/lychee-lib/src/collector.rs
Lines 122 to 145 in 8fd34a7
It indirectly affects local file support if there a lot of files to handle (as in the sentry example).
The better approach is to lazily evaluate each file e.g. by using a stream. I will play around with streams a bit to see if I can build something fast and efficient. If anyone wants to help me with that, feel free to create a test repo, a pull request or we can even pair program on this together (UTC+2 timezone).
lebensterben commentedon Sep 11, 2021
one solution is to make this synchronous. tokio is able to spawn synchronous task within asynchronous context.
if you want, you can use crossbeam/rayon to start a dedicated thread pool with limited number of OS thread.
lebensterben commentedon Sep 11, 2021
see
https://docs.rs/tokio/1.11.0/tokio/#cpu-bound-tasks-and-blocking-code
local disk IO is not CPU bound. we'd expect most files are processed below 10s (the default timeout before tokio steal a thread), so using asynchronous here isn't really helpful either.
and suppose tokio really does steal from a thread, that only adds unnecessary cost of context switching.
lebensterben commentedon Sep 11, 2021
ripgrep uses crossbeam + num_cpus.
in particular, its "worker" is synchronous in nature, even when multi-thread is on.
https://github.com/BurntSushi/ripgrep/blob/df83b8b44426b3f2179abe632eb183e8c8270524/crates/core/search.rs#L310
it's relatively cheap for us to factor out the network IO from other parts, and use tokio and crossbeam, respectively, for local and network IO.
roughly speaking,
mre commentedon Oct 7, 2021
For some reason I only see your comments now. What you say all makes sense and we should go forward with that.
As you mentioned, we can take a lesson from ripgrep's book. Since ripgrep and lychee and many others seem to have the same requirements for fast filesystem traversal, I wonder if there should be a separate crate, which can wrap that functionality behind a nice, performant interface. But yeah, rayon sounds like a good idea and spawn_blocking sounds like a great combination.
untitaker commentedon Oct 7, 2021
Jwalk already implements walkdir on rayon, I've found it to be on-par with custom rayon or ripgrep. That said if you want to honor gitignore etc maybe you want to look at ripgrep. I just didn't find their code particularly reusable (relatively speaking)
mre commentedon Oct 7, 2021
jwalk looks great. We should use that if the input is a directory. Would be nice to add glob support to it, but it might be out of scope for the crate. 🤷
ripgrep probably covers more edge-cases, but as you said it's not very reusable as a library, so jwalk is probably our best option.
mre commentedon Oct 10, 2021
Added jwalk to #330.