Friday, February 23, 2024
Friday, February 9, 2024
Thursday, December 14, 2023
Java: streaming WARC files
Previously, I published in a separate post a minimal example of some Java code that reads WARC data, using the "jwat-warc" library. After that, I wanted to compare the performance of the two major WARC parsing libraries ("jwat-warc" and "jwarc"), in the context of a more complex process.
The difficulty in doing this is that the major libraries have different approaches to how they expect you to consume the data.
e.g.
- "jwat-warc" exposes a stream of the underlying HTML, while "jwarc" exposes a stream containing both the underlying HTTP headers and the HTML.
- "jwat-warc" exposes the HTTP response code, while when using "jwarc" they have to be extracted from the headers.
- etc.
public abstract class XWarcRecord {
protected String _uri;
protected String _payload;
abstract public String responseCode();
abstract public String payload();
return new XWarcRecord_JWat(r);
}
return new XWarcRecord_JWarc(r);
}
}
And the particular implementations, with some optimizations to defer as much processing as possible to the time when a particular data point is needed:
I. "jwat-warc"
For some reason, if you don't read the stream manually, the reader will throw an error when advancing to the next record. So we have to do that in the constructor.
II. "jwarc"
The stream they expose includes both the HTTP headers and the HTML (or other content), so we have to extract them manually.
Monday, December 11, 2023
Throttle vs Debounce
The following page will offer a very nice JavaScript illustration of the difference between throttle and debounce: https://web.archive.org/web/20220128120157/http://demo.nimius.net/debounce_throttle/
The terms make sense in the context when you want to control the time when an "effect" is triggered, based on the timing of the "cause" (I am using these terms very generally: "cause and effect").
You "throttle" when you want the effect to be spaced apart by a minimum interval of X time.
You "debounce" when you want the effect to be triggered after the cause has "cooled off" for enough (X) time.
Friday, December 8, 2023
Install Node.js / npm on Linux
The easiest way to manage Node.js / npm on Linux is by using the Node Version Manager:
https://github.com/nvm-sh/nvm
I. Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
II. Use NVM to install the latest LTS release of Node.js / npm
nvm install --lts
III. List versionsV. Install a specific version
Saturday, November 25, 2023
IMDSv2
v2 of the AWS "Instance Metadata Service" has been around for a while.
- It is optional for now, but they will make it mandatory some time during 2024 [1].
- The IMDS has to do with how EC2 instances get their metadata and IAM permissions.
- If you're using a recent version of cloud-init, AWS CLI and SDKs, these should support v2.
- By default, most instances that have been around for a while still use v1.
To list instances that are still using v1 [2]:
aws ec2 describe-instances \
--filters "Name=metadata-options.http-tokens,Values=optional" \
--query "Reservations[*].Instances[*].[InstanceId]" \
--output text
To enable v2 on a per-instance basis:
aws ec2 modify-instance-metadata-options \To change an AMI so that instances launched from it have v2 enabled:
aws ec2 modify-image-attribute \--imds-support v2.0
You will have to change how you retrieve instance metadata URIs [3].
v1:
curl -s http://169.254.169.254/latest/meta-data/instance-id
v2:
TOKEN="$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")"curl -s -H "X-aws-ec2-metadata-token: $TOKEN" \
References:
- https://aws.amazon.com/blogs/aws/amazon-ec2-instance-metadata-service-imdsv2-by-default/
- https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-metadata-transition-to-version-2.html
- https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-metadata-v2-how-it-works.html
Thursday, November 9, 2023
Debugging Linux input events
I recently had some issues with a laptop running Linux receiving spurious keyboard events.
The following two commands are useful in debugging this:
sudo tail -f /dev/input/event*
And:
xinput test-xi2 --root 5
You can replace the "5" with any other value to view input from other devices.