Tuesday, October 31, 2023

Failing to use a supported namespace gives you "Operation not supported"

Today I was trying out the xattr thing today and I kept getting Operation Not Supported error I couldn't figure it out until I tried the example code...yeah it turns out you have to use a namespace for the attribute like user.foo, if you use foo then it won't work.

So this works:

err := unix.Setxattr("/tmp/hi.txt", "user.foo", []byte("test-attr-value"), 0)

But this will give you Operation Not Supported:

err := unix.Setxattr("/tmp/hi.txt", "foo", []byte("test-attr-value"), 0)

You also get this error if you use a namespace other than user:

err := unix.Setxattr("/tmp/hi.txt", "foo.bar", []byte("test-attr-value"), 0)

Sunday, October 29, 2023

What if YouTube used the tarsnap pricing model?

I hate ads but I don't want to pay for YouTube Premium.

Relevant Abstruse Goose (447 - Important Messages):

Tarsnap uses a prepaid model based on actual usage:

Storage: 250 picodollars / byte-month of encoded data
($0.25 / GB-month)
Bandwidth: 250 picodollars / byte of encoded data
($0.25 / GB)

What if YouTube used a similar model? Then the hosting and bandwidth costs could be "fairly" distributed among users based on how much video content they consume. So if they watch more videos then they pay more, if they watch less then they pay less.

Anyway, I think $0.25/GB for bandwidth is FUCKING CRAZY in what fucking universe does it make sense to charge 25 cents per GB for bandwidth. AWS only charges $0.09 per GB for download which is still insane - AWS (like most cloud providers) is absolutely charging their customers through the fucking nose for egress. It definitely doesn't cost them even 1 cent per GB. This is DUMB. Hetzner charges €1/TB for bandwidth egress. You read that right - €1 per 1000GB, or around 0.1 cents per GB. Okay so maybe tarsnap is doing some really expensive computations per GB transferred but I doubt it adds up to that much.

Anyway I think YouTube could use a similar pricing model, except use a saner bandwidth cost like €1/TB like how Hetzner does it. I guess most users won't even use that amount in a month. Even if they charged €10/TB like BackBlaze does I doubt most users would even use €5 per month in bandwidth.

HD video is about 1-3GB per hour. Let's be generous and say it's 5GB per hour. So if you are watching 5 hours of 1080p video every day that is 25GB data usage per day which at 1 cent per GB works out to 25 cents per day, which is around $7.50 a month. If you only watched 2 hours of 1080p video per day then it would be $3 per month. And then there are people who mainly use YouTube to listen to music or podcasts, which uses way less data.

And that's based on the 1 cent per GB bandwidth model which BackBlaze uses. If they used the 0.1 euros per GB model like Hetzner does it would be like 10x lower than that, most people probably wouldn't even pay $1 a month.


Actually, I think if they just made a YouTube Basic Membership that costs $1 a month but allowed you to watch say 100GB of ad-free video and then you can pay another $1 to watch another 100GB of ad-free video I think that would work quite well. I would be happy with that.


Anyway, that's just some thoughts I know YouTube doesn't care about my ideas and tbh I don't know their business problems or domain that well anyway so all this is just a waste of time but it's just based on the simple thought of "what if YouTube charged its users by the amount of resources they actually use" and I think the answer is, it would be nowhere near the amount they charge for YouTube Premium.

GOD DAMMIT 😡😡😡 In Go, it is impossible to specify that an argument must be a struct 😡😡😡😡😡

So I want the Go compiler to check that an argument is a struct but there is no way to specify this using the Go programming language. Pee Jai had the same issue:
 

Pee Jai
Jun 24, 2020, 2:28:58 PM
to golang-nuts
Here is my use case: https://godoc.org/github.com/rocketlaunchr/react#UnmarshalState

That function has an argument that accepts only a struct. I use the reflect package to iterate over the structs fields (and also to check if it actually is a struct). The function has notapplicability for non-structs.

Currently I have to notify the user via documentation that only a struct is allowed since the type is officially an `interface{}`. This is very crude.

If there was a way to add a type constraint for only structs, then I don't need to use documentation, notwithstanding the use of reflect package to iterate over the struct fields.

 

 

Ian Lance Taylor
May 19, 2022, 3:41:29 AM
to Jeremy Kassis, golang-nuts
On Wed, May 18, 2022 at 7:36 PM Jeremy Kassis <jka...@gmail.com> wrote:
>
> Where exactly did this land? Seems like an important conversation...

To date there is no way to write a constraint that requires that a
type argument be a struct type.


So annoying! I have to use reflection to check it...god dammit!

I can't believe I can't specify that an argument must be of struct type...wtf!

Saturday, October 28, 2023

Benchmarking brute force vs Trie longest prefix matching implementations in Go

I wanted to do longest prefix matching for my web server which checks URLs against a list of prefixes and returns the longest matched prefix.

I wanted to know when the trie implementation was faster than the brute force implementation so I wrote a little benchmark.

The benchmark is here:  https://github.com/1f604/longest_prefix_go

My implementations are the simplest possible i.e. not super optimized, but we are talking about 0.8s for 100k searches, which is 8 microseconds per search for 200 prefixes, for the brute force method. The trie method is about the same speed.

So we are really talking 8-10 microseconds per search when you have 200 prefixes. 

Results suggest that brute force is faster when number of prefixes is less than 200, but Trie is faster when number of prefixes exceeds 300.

You may get different results on your machine.

Monday, October 23, 2023

got hit by bug with AppendFormat, now I want a linter that warns on unused return values

So I just got hit by a bug where I didn't use the return value of time.Time.AppendFormat

It's surprising because the compiler warns me about unused append() but doesn't warn me for AppendFormat which does basically the same thing. 

It's completely useless to call AppendFormat if you don't use the return value but neither the compiler nor any of my linters caught that.


So now I want a linter that warns on unused return values.

Currently go vet has unusedresult but it's a blacklist - you have to specify the functions that you want it to check, which is not very useful.

I want a whitelist but it doesn't have that.

URGH this is so ANNOYING!!! Especially because AppendFormat was recommended by one of the linters I was using. GRRRR

I've raised an issue on the Golang Github repo: https://github.com/golang/go/issues/63689