News for hackers. Stuff that matters.
Re:Website hosted on a 24 year old Linux server by sillysaurusx on Thursday April 06, 2023 @11:01AM (#35469241)
I remember how magical and mysterious a view counter used to feel when I was a kid. How did the website know when someone visited it? Where was the count stored? And how on earth could a website update its own HTML to show the new count?

Geocities days were magical. I wonder if kids today have similar thoughts about Twitter profiles and such. It’s probably much easier to pick up the knowledge — back then, it was balkanized across IRC and whatever we used before Google.

I also started writing a FF7 walkthrough all on a single page, because I didn’t know how to link from one page to another. I made the different chapters different font colors, reasoning that it was good enough to change the color when you’re trying to figure out which section to get to. Good times…

EDIT: Whoa. The view count is real time. You can see how quickly HN is hammering the page by refreshing it. The guestbook works too. I wonder what the tech stack looks like.

Doing this in modern times would be so complicated. You’ll need a database, then software to talk to the database, and maybe webpack.

Re:Website hosted on a 24 year old Linux server by seba_dos1 on Thursday April 06, 2023 @11:17AM (#35469493)
> Doing this in modern times would be so complicated.

No, it wouldn't. All you need to store this kind of data is a simple file. Most people would probably use PHP for something like that due to its ubiquity, but it could even be a few lines of bash, or Python, or Go, or whatever...

Re:Website hosted on a 24 year old Linux server by ElectricalUnion on Thursday April 06, 2023 @11:39AM (#35469897)
> All you need to store this kind of data is a simple file.

You mostly likely need a WAL Mode SQLite database. Most of the time, it's way simpler that handling state handling in concurrent situations yourself. (also, bindings are often available - if not outright bundled by default - under most common languages)

The "easy" way is all fun and games until your file is accessed in a concurrent fashion, and then your options are:

a) flat out die when concurrent things happens (file locks; default sqlite3 behaviour);

b) just write blindly to file and pretend concurrecy doesn't exist, but randomly lose data - (write to files directly like a crazy person; sqlite3 PRAGMA schema.synchronous = OFF)

c) allow reading at anytime, but serialize writing somehow (file locks + write + move atomic file operations; append writing and a journal; sqlite3 PRAGMA journal_mode=WAL)

Re:Website hosted on a 24 year old Linux server by Supermancho on Thursday April 06, 2023 @11:53AM (#35470155)
> You mostly likely need a WAL Mode SQLite database

Or redis.

Re:Website hosted on a 24 year old Linux server by doublerabbit on Thursday April 06, 2023 @11:53AM (#35470159)
> You mostly likely need a WAL Mode SQLite database.

Overkill, If you are writing to the text file only to increment a number of visitors, none of what you mentioned above is even required.

Create a "counter-hit" file for each visitor, count the number of files in the resources directory. Populate the master file with the file count and delete all the temporary files. Configure it on a crontab for say every three seconds.

Online now was even easier. IFrame refresh within the homepage. Upon refresh, populate the file with something like "online=true". Read the file every X, if the file modifcation hasn't been refreshed within 30 seconds, nerf the text file and mark that user as offline. psuedo-dynamic, but times were different then. I coded these in perl back in the day for my RTCW clan and how I miss it much.

Being a webmaster was art, an art that's now lost..

Re:Website hosted on a 24 year old Linux server by artificial on Thursday April 06, 2023 @12:32PM (#35470802)
64 Player Depot. I always had a fondness for Tram. Played CAL Main. Good times. v43
Re:Website hosted on a 24 year old Linux server by jcalvinowens on Thursday April 06, 2023 @12:07PM (#35470412)
It can be much simpler if you're willing to write a couple lines of assembler: use an 8-byte file that contains one 64-bit counter, mmap() it, mlock() it, and use atomic CPU instructions to increment and read it.
Re:Website hosted on a 24 year old Linux server by andoma on Thursday April 06, 2023 @06:12PM (#35475242)
Genuine question: Does it have to be mlocked for this to work?
Re:Website hosted on a 24 year old Linux server by wahern on Thursday April 06, 2023 @08:37PM (#35476569)
You don't need mlock for the interprocess atomicity. There may be a race if you intend the file to be persistent; write-back to disk wouldn't necessarily be atomic. But mlock doesn't solve that problem, it just might make it slightly less likely to result in corruption if it means less flushing. To truly solve it you need a proper synchronization mechanism, e.g. a mutex to quiet all writers, then a blocking sync. OTOH, write-back for a single native integer may actually be atomic, assuming it doesn't cross a cache line, so in practice a simple mmap may be sufficient. (I emphasize may, though. I'm not that familiar with the inner mechanics of DMA, block device buffering, etc.)

You don't need assembly, either, as standard atomic built-ins in C, C++, etc, will work just fine, as will FFI to such built-ins.

Re:Website hosted on a 24 year old Linux server by jcalvinowens on Friday April 07, 2023 @09:15PM (#35489374)
Great question: it does not! It just removes a potential source of stalls.

If the page isn't resident in the page cache, the thread(s) executing the atomic increment will take a page fault and be blocked until the file data is read from storage. The latency of the fault might be significant, but the counter will remain accurate.

There's an important caveat I should have added: the counter file might be very stale after a power failure. If you care about the counter integrity, you have to msync(MS_SYNC) periodically, and that's expensive. It might actually stall all threads interacting with the page, depending on the filesystem; that used to be true but I'm not certain it still is (see https://lwn.net/Articles/486311/). Where writeback is allowed to race with writes, whether you would be guaranteed the 8-byte value written back wasn't "torn" without explicitly blocking increments while syncing is also an interesting question if DMA is involved...

Re:Website hosted on a 24 year old Linux server by malborodog on Thursday April 06, 2023 @07:51PM (#35476175)
I am going to ask gpt 4 to implement this for me so I can see what it looks like. Amazing.
Re:Website hosted on a 24 year old Linux server by Gud on Friday April 07, 2023 @08:55AM (#35481094)
How did it go?
Re:Website hosted on a 24 year old Linux server by jcalvinowens on Friday April 07, 2023 @09:39PM (#35489535)
I have to go to dinner so this isn't finished, but this is most of the code to prove it works: https://gist.github.com/jcalvinowens/0d7a5c327d863fca7c84daa...
Re:Website hosted on a 24 year old Linux server by henrydark on Thursday April 06, 2023 @12:19PM (#35470599)
Sqlite?? MS Access for the win!
Re:Website hosted on a 24 year old Linux server by seba_dos1 on Thursday April 06, 2023 @12:34PM (#35470831)
For guest book, you don't need anything like that. A simple solution could be to create a file for each entry. It's append-only anyway.

For a view counter - yes, you can use a full blown database to concurrently increment a simple integer value; or, you could do it in a few lines of code by yourself too.

Re:Website hosted on a 24 year old Linux server by loo on Thursday April 06, 2023 @01:04PM (#35471267)
$ apt install redis-server

$ redis-cli INCR hit-count

Re:Website hosted on a 24 year old Linux server by seba_dos1 on Thursday April 06, 2023 @02:49PM (#35472679)
Still a huge overkill, and you need to properly set up persistence if you use it this way.

If you know that you'll need a cannon anyway, then sure, go for it, but when all we deal with are flies there's no reason to go that far. You could easily set up this kind of website on servers so simple that getting redis running on them would inflate their complexity quite considerably.

Re:Website hosted on a 24 year old Linux server by SoftTalker on Thursday April 06, 2023 @05:32PM (#35474799)
> b) just write blindly to file and pretend concurrecy doesn't exist

This is likely what was done. Nobody really cares if a hit counter on a web page loses a few updates.

Re:Website hosted on a 24 year old Linux server by mappu on Thursday April 06, 2023 @06:21PM (#35475317)
Given it's a single-threaded CPU, there's a fair chance the web server isn't concurrent anyway.

Linux got proper POSIX thread support with NPTL only in 2002.

Re:Website hosted on a 24 year old Linux server by electroly on Thursday April 06, 2023 @08:06PM (#35476300)
The RaQ line used Apache which definitely supported concurrent requests. We're talking about 1999 here. Maybe this isn't as obvious to people today looking back, but concurrent request handling was absolutely required from the beginning: consider how slow your clients are! One single client on a slow dial-up modem can't be allowed to drag the whole site down.
Re:Website hosted on a 24 year old Linux server by johannes1234321 on Thursday April 06, 2023 @08:07PM (#35476316)
It will be a forking web server. But the CPU scheduler will schedule process A while B is opening the file and reading and that. While B is then increasing the counter, leading to multiple processes with "wrong" data.l racing for the writes.
Re:Website hosted on a 24 year old Linux server by randomdata on Thursday April 06, 2023 @09:05PM (#35476773)
As I remember it, you would flock the file. You didn’t care if another process blocked for the short period it was held. It is not like you were getting huge amounts of traffic.
Re:Website hosted on a 24 year old Linux server by jszymborski on Thursday April 06, 2023 @06:36PM (#35475462)
You can do (c) in python with flock

https://www.php.net/manual/en/function.flock.php

Re:Website hosted on a 24 year old Linux server by johannes1234321 on Thursday April 06, 2023 @08:12PM (#35476362)
I think you can avoid the lock and all else, if all you need is a counter: Open a file in append mode (O_APPEND) and then write a byte for each visit. To get the count take the file size.

Of course you have to make sure to not run out of diskspace or max file size of the OS/filesystem (2GB on a 32bit system?)

Re:Website hosted on a 24 year old Linux server by error503 on Thursday April 06, 2023 @08:13PM (#35476373)
d) write to a temp file and atomically move it onto the read path. you will miss counts, but nothing will break.
Re:Website hosted on a 24 year old Linux server by anacrolix on Friday April 07, 2023 @03:30AM (#35479099)
I think you mean journal mode off. Synchronous off is nothing to do with concurrency.
Re:Website hosted on a 24 year old Linux server by zitterbewegung on Thursday April 06, 2023 @11:12AM (#35469419)
Geocities got reincarnated as https://glitch.com/ and it has many more features and you can clone others sites or starter packs.
Re:Website hosted on a 24 year old Linux server by nyolfen on Thursday April 06, 2023 @11:40AM (#35469917)
i think neocities would be the more direct analogue https://neocities.org/browse
Re:Website hosted on a 24 year old Linux server by davb on Thursday April 06, 2023 @11:50AM (#35470114)
I'd say https://neocities.org/ is the modern reincarnation of Geocities.
Re:Website hosted on a 24 year old Linux server by EvanAnderson on Thursday April 06, 2023 @11:52AM (#35470149)
(I'm probably getting some details wrong here because this was all nearly 30 years ago, but anyway...)

The realtime hit counter and fascination therewith brought up a memory.

Back in '95 the regional dial-up ISP I used offered personal website hosting on one of their boxes (the standard http://www.isp.com/~username gig). I was very excited to put up a personal website. That was fun for awhile but soon I wanted to do more with it. I liked the look of hit counters, guest books, etc.

I became annoyed because this "CGI" thing I'd read about didn't work. I could FTP up Perl scripts named with ".cgi" filenames, however accessing them only resulted in seeing the Perl code.

I setup a webserver (NCSA httpd) on my Slackware box and started experimenting. I learned about .htaccess files and, more importantly, learned I could override the server's main httpd.conf with directives in my directory's .htaccess file.

A little experimenting with my ISP's web server turned up that, sure enough, they had not configured "AllowOverride None". Lo and behold I could enable server-side includes[0] in my directory-- including executing CGIs via SSIs!

Once I figured out how to chmod +x my scripts thru the FTP server I was in business. I had a hit counter! I had a script to check the referer (sic) and add a link in the footer back to the "main page" if you didn't "come from" there. I wrote out my own log files (because I didn't have access to the server's main log file) so I could see the IPs, user agent strings, and referers of visitors. (I also learned about file locking and parallel execution of the script by multiple requests occurring simultaneously. Fun!)

(The ISP didn't offer shell access but I figured out, pretty quickly, that I could write a rudimentary web shell with my SSI-based CGIs. I didn't do too much with that because I didn't want to get caught and I'd mostly gotten the desire to do "unauthorized pro-bono remote system administration" out of my system by that time...)

This little "site" my friend and I ran got listed on Yahoo (we submitted it... >smile<). I remember seeing a bunch of clients with reverse-lookups of the form "xxx.yahoo.com" that day.

Wired had recently done an article on Yahoo[1]. I saw a client named "srinija.yahoo.com" and remembered the article talked about a "Srinija Srinivasan" being an employee there (working on ontology). It was really exciting to see somebody named in a Wired article accessing my silly little site. (The most memorable client name from Yahoo was "ratbastard.yahoo.com", BTW. I'd love to know the backstory. Guess I already wrote about this once...[2])

[0] https://www.oreilly.com/openbook/cgi/ch05_01.html

[1] https://www.wired.com/1996/05/indexweb/

[2] https://news.ycombinator.com/item?id=16741431

Re:Website hosted on a 24 year old Linux server by xwdv on Thursday April 06, 2023 @11:56AM (#35470230)
Young kids today do not have any kind of thoughts about the workings of apps they use any more than they have thoughts about how their favorite shows or movies are made, or how their house was built, or how a car works.
Re:Website hosted on a 24 year old Linux server by 2b3a51 on Thursday April 06, 2023 @12:23PM (#35470667)
Round here some of the teenagers show promise as tinkerers.

Reverse engineering the e-scooters so you don't have to pay is popular.

Old cars everywhere being rebuilt and modified.

One guy has added a small engine to his pushbike using some kind of gear wheel coupling.

They are making their own short films and fashion shoots now the Sun is out. Lets face it a smartphone is all you basically need to create (some kind of) media now.

Re:Website hosted on a 24 year old Linux server by sgt on Thursday April 06, 2023 @01:20PM (#35471497)
DIY is huge in 2023. Just look at YouTube.
Re:Website hosted on a 24 year old Linux server by wellanyway on Thursday April 06, 2023 @12:27PM (#35470719)
Yelling at sky much?
Re:Website hosted on a 24 year old Linux server by bee_rider on Thursday April 06, 2023 @12:12PM (#35470483)
If by young kids, you mean college students, hahaha.
Re:Website hosted on a 24 year old Linux server by lostlogin on Thursday April 06, 2023 @10:41PM (#35477373)
This is a very HN take on ‘kids these day’ complaints which seem to go back as far as human records do.

https://www.reddit.com/r/history/comments/7btv14/the_more_th...

Re:Website hosted on a 24 year old Linux server by johnbellone on Thursday April 06, 2023 @12:08PM (#35470423)
I feel like you could do this without a database using the Linux kernel inotify API. Every time a file is accessed trigger an increment. It’s too beautiful of a day outside to try this right now but an interesting brain teaser!
Re:Website hosted on a 24 year old Linux server by LorenDB on Thursday April 06, 2023 @12:11PM (#35470467)
> It’s too beautiful of a day outside to try this right now

That's what laptops are for!

Re:Website hosted on a 24 year old Linux server by stronglikedan on Thursday April 06, 2023 @12:45PM (#35471004)
If you're just sitting outside, you may as well be inside.
Re:Website hosted on a 24 year old Linux server by hammyhavoc on Thursday April 06, 2023 @12:54PM (#35471122)
My mood says otherwise.
Re:Website hosted on a 24 year old Linux server by prmoustache on Thursday April 06, 2023 @02:23PM (#35472333)
Only if your laptop has some e-ink/e-paper tech screen really.
Re:Website hosted on a 24 year old Linux server by hammyhavoc on Thursday April 06, 2023 @02:46PM (#35472632)
Sitting in the shade works for me, but yes, e-ink or STN works well (decades-old tech).
Re:Website hosted on a 24 year old Linux server by SoftTalker on Thursday April 06, 2023 @12:44PM (#35470987)
Pretty sure Linux didn't have inotify then.

Probably a CGI script updates a counter in a file.

Re:Website hosted on a 24 year old Linux server by smashed on Thursday April 06, 2023 @01:14PM (#35471414)
Can confirm, that's how it was done. A simple text file.
Re:Website hosted on a 24 year old Linux server by yjftsjthsd-h on Thursday April 06, 2023 @02:18PM (#35472252)
> Pretty sure Linux didn't have inotify then.

Did FUSE exist yet? You could hack it up in userspace...

(Have the HTML on a FUSE filesystem, and every time it gets a read it updates the HTML)

Re:Website hosted on a 24 year old Linux server by dmd on Thursday April 06, 2023 @04:50PM (#35474216)
Re:Website hosted on a 24 year old Linux server by Zach_the_Lizard on Thursday April 06, 2023 @05:47PM (#35474987)
What about dnotify? I think that predated inotify. If so, I think it has the ability to notify a process when a file was accessed, so could fill a similar role.
Re:Website hosted on a 24 year old Linux server by treeman79 on Thursday April 06, 2023 @05:39PM (#35474888)
Would be flying with all the bots trying to hack Wordpress bugs
Re:Website hosted on a 24 year old Linux server by bennyp101 on Thursday April 06, 2023 @12:27PM (#35470725)
Pretty sure the first guestbook/counter I wrote were in perl and wrote to a text file :D
Re:Website hosted on a 24 year old Linux server by washadjeffmad on Thursday April 06, 2023 @12:30PM (#35470771)
There are (still) dozens of us!
Re:Website hosted on a 24 year old Linux server by warner25 on Thursday April 06, 2023 @12:30PM (#35470779)
> I wonder if kids today have similar thoughts

I'm sure that some do, and most don't. Most kids 30 years ago didn't have similar thoughts either. Few people are meant to be programmers, engineers, etc. Were you not shunned as a nerd for having an interest in how computers worked?

Re:Website hosted on a 24 year old Linux server by doublepg23 on Thursday April 06, 2023 @12:42PM (#35470957)
> Were you not shunned as a nerd for having an interest in how computers worked?

I certainly wasn’t in the 10s. Usually people would come to me and my nerd buddies for PC building advice, smartphone advice, and of course the occasional “can you pirate this for me” request ;)

Re:Website hosted on a 24 year old Linux server by hammyhavoc on Thursday April 06, 2023 @12:54PM (#35471115)
Tech had long since gone mainstream by that point though as the barrier of admission was lowered significantly, it was no longer the hobby of nerds.
Re:Website hosted on a 24 year old Linux server by doublepg23 on Thursday April 06, 2023 @11:29PM (#35477697)
I would still say the people in Linux club were _nerds_ but the platonic ideal of “nerd” had shifted from what it was in the 80s/90s.
Re:Website hosted on a 24 year old Linux server by yamtaddle on Thursday April 06, 2023 @06:26PM (#35475365)
I think the early-00s was when it started to shift from something stigmatized to something that a person could be into and still be cool—or, at least, not regarded as automatically weird. By 2010 the shift was basically done, and The Great Techbro Wave was washing over the industry.

It's been super weird to watch the common idea of a computer person shift from someone with bad skin and shit posture in a pit-stained button-up and thick-rimmed glasses and who rarely sees the sun, to a trim, decent-looking person who's into rock climbing and wears lots of new, clean clothes from Patagonia. It was a really fast transition, in hindsight.

Re:Website hosted on a 24 year old Linux server by warner25 on Thursday April 06, 2023 @06:37PM (#35475465)
Back when I was in college in the mid-00s and TheFacebook was cool, because it was still limited to people with .edu email addresses from top-tier and Boston-area schools, I remember a group named "I'm a Computer Science Major and I Shower Regularly." I joined it even though I probably didn't shower regularly enough.

(For those who didn't have access to TheFacebook in those days, joining groups was part of how we expressed our political views, interests, sense of humor, etc. Groups had a name and a photo and a list of members and often served little other purpose.)

Re:Website hosted on a 24 year old Linux server by SoftTalker on Thursday April 06, 2023 @12:34PM (#35470833)
> Were you not shunned as a nerd for having an interest in how computers worked?

I remember those days. There was one table in the lunch room where the 10 or so kids who were into computers sat. I found out later talking to some other classmates that nobody else wanted to talk to us because they thought they weren't smart enough.

Re:Website hosted on a 24 year old Linux server by hammyhavoc on Thursday April 06, 2023 @12:52PM (#35471098)
Christ, that there were other kids with an interest in computers is amazing. I sat on my own lmao.
Re:Website hosted on a 24 year old Linux server by warner25 on Thursday April 06, 2023 @02:15PM (#35472201)
I had a friend to sit with at lunch and talk to excitedly about computers, PC gaming, robots, military hardware, etc. This was in the 90s.
Re:Website hosted on a 24 year old Linux server by hobo_in_library on Thursday April 06, 2023 @05:14PM (#35474556)
you guys had friends?
Re:Website hosted on a 24 year old Linux server by Gasp0de on Thursday April 06, 2023 @12:55PM (#35471143)
Why would it be more complicated today than back then? Just use Python, write the view counter into a text file and use javascript with polling (or websockets) for the realtime refresh.
Re:Website hosted on a 24 year old Linux server by Eumenes on Thursday April 06, 2023 @06:00PM (#35475132)
you could do this on an ftp server, no need for webpack and databases
Re:Website hosted on a 24 year old Linux server by geenat on Friday April 07, 2023 @12:19AM (#35477993)
Similar to how the upcoming WAL2 works in SQLite, could do it atomically or "concurrent safe" like:

- Main count file.

- 2 "Append" files.

======

- Append 'a' to append file 1.

- After some time, swap append file 1 with 2.

- Count up 'a' in non-active append file 1, add it to main count.

Then just repeat, swapping append files.