- The user sends an HTTP request to somesite.com
- Their DNS query for somesite.com gets resolved to some datacenter near them
- The HTTP request arrives at the datacenter where the PHP in WebAssembly is executed at half the speed of native PHP
- The PHP in Webassembly sends database queries to a central DB server over the internet
- The PHP in Webassembly templates the data and sends it back to the user
How is that faster than resolving somesite.com to the central server, sending the HTTP query to the central server where PHP runs at full speed and talks to the DB on the same machine (or over the LAN)? Even if PHP ran at full speed at the "Edge", won't the two requests over the internet user --1--> edge PHP server --2--> central Db server
take longer than the one http request when the user connects to the central server directly? user --1--> central PHP+DB server
In reality, the PHP script on the "Edge" server probably makes not one but multiple queries to the DB server. Won't that make it super slow compared to having it all happening on one machine or one LAN?Of course there are always exceptions. Often stale data is ok and you can ship data snapshots to the edge so that they can be served without going back to the central DB. But in many cases some basic cache policies with a CDN can be nearly as effective.
Are you saying it would result in a better user experience when I only use host1 which is behind the CDN and add no-cache headers to the request that can't be cached?
Some other providers have tried to solve the problem with replicated databases that are used for local reads.
I can't go into details yet, but Wasmer will offer a solution for this problem quite soon as well, which hopefully will be much more seamless than existing strategies.
(note: I work at Wasmer)
I've personally seen this with a game recently and my own ISP. I can ping their West Coast servers in 20-40ms while pinging their Chicago servers takes 200ms+.
This is actually one huge flaw with the current way IP is done. Because your ISP is closely tied with the last-mile of routing, you have very little control over optimizing those backend layers of routing.
This doesn't explain why you wouldn't just run a thin proxy at the edge and instead want to run a full PHP app. For that, my guess is this makes sense when you don't want to run a full server all the time or if you want it to be rapidly scalable.
You do caching so you don't always have to go back to the DB is the main thing. The other interesting capability is light scripting at the edge. Think "this page is cached but I'm going to add in a custom username".
There's some more exotic stuff around sharded database locality. But I'll skip over that because distributed mutable state is hard and its not my specialty.
Connection warming and shorter tls negotiation round trip times are also a thing but probably less important compared to the database thing you are mentioning.
But mostly this architecture makes sense if you can do some caching or if you're doing more data/log collection stuff.
For prior work see ESI (edge side includes). Assembling stuff at the edge does have some benefits but it has been hard to create a good interface for that.
Unless you host the database in the same network as your edge provider, appliation <-> database is where the bottleneck is.
For example, a form builder like typeform could cache form definitions on edge and render them close to users. Submissions would require db communication but the entire experience could be better.
Otherwise it is just not worth it.
BTW, I don’t even think PHP running slower in wasm would be that important. These things generally depend on IO performance rather than runtime if you are not doing a lot of calculations on the edge. WASM is also pretty fast these days so..
ironically everything is petty fast and everyone waste that speed adding things that allow for a cheaper labour. wasm included. it went from a "have some expertly optimized code in the browser" to "just compile this hide cpp thing and ship as a react component" to then "it allows our servers to run any crap without knowledgeable staff in each language"
we added so many Layers to cheapen labour that now all the labour costs goes into managing the Layers.
I agree with you, and it's not faster. With the risk of sounding old (get off my lawn): I assure you the megabytes of unneeded Javascript they're downloading to the client are ten times slower to execute than the milliseconds they may be saving on the wire.
Client talks to closest system, TLS gets terminated as soon as possible.
Certain things can be cached on edge which normally can't be cached just through basic http (like as soon as you are logged in).
So if your website receives no requests, it costs you nothing. And requests have less latency for the user.
That's the theory anyway, in my experience reality is a lot more nuanced because the serverless node still has to reach a database and so on.
For most general-purpose applications, there’s no point to WASM. But some apps may run specific functions which take a long time (e.g. bulk/batch processing), and being able to execute those tasks securely on the client side provides immediate feedback and better UX.
That’s just one use case. Another is that WASM makes PHP portable, in the sense it can run in any web browser without the need for a back-end server. Lots of potential opportunities for distributing software which runs completely locally.
Also not to be confused with the term edge within the context of IoT/embedded, where the edge is devices running at the very edge of the Internet, e.g., factory floors, trucks, etc.
But you are completely right pointing out that there's still some room to improve, specially when compared to running PHP natively.
Right now there's some price to pay for the isolation and sandboxing, but we are working hard to reduce the gap to zero. Stay tuned for more updates on this front!
FrankenPHP is also really good and probably a much smarter play than trying to get your code running under WebAssembly.
The latter will always be faster.
If you’re on PHP and need more speed in the language itself, basically every other scripting language (yes, including Node) is off the table immediately. Lateral move at best.
(All that to say, yeah, I entirely expected that the headline would lead to an article about making PHP slower)
Which is also the reason why a lot of the PHP standard library functions are so inconsistent. They're straight wrappers around the C libraries.
Upside is, unless you have to do shit with pointer magic or play around the edges of signed/unsigned numbers, it's fairly easy to port C example code for any of the myriad things PHP has bindings to to PHP.
The latter will always be faster.
"What if our code ran in tens of thousands of different environments that we have no control over, rather than a single server environment we control!"
Various interpreters might or might not have a good capability/permissioning model (Java's is capable but complex and not supported by many applications, for example); even if they do, there might be exploitable bugs in the interpreter itself.
I find WASM interesting from a technical perspective, but not from a practical one.
Also, not everything requires a database.
The way I understand it is that is moving some operations closer to the client to avoid bandwidth costs and improve performance.
I thought of the Tesla car computer as edge computing, as it does a lot of processing within the car that would otherwise add latency and reliance on a internet connection.
But for web browsers? Going to some websites?
What sort of apps need this functionality?
Seems like over-engineering, so I'm looking for someone to explain me.
1. latency
2. intermittent access
3. distributed "meaningful" data preparation/filters
One may consider routers with squid proxies, VoIP trunks, and p2p cache are essentially similar "edge" technologies.
There are additional use-cases, but we don't want to educate the lamers stealing resumes off jobs sites... having no clue what they are talking about.
Have a nice day, =)
Edge means getting embedded into ISP networks, cell towers, smaller metros, etc.
This is like the owner of a restaurant with two locations in the same city calling themselves a nationwide chain. It is just a flat out fabrication.
>> Ask HN: What are your predictions for 2024?
> Server-side WASM takes off with the re-implementation of PHP, Ruby/Rails, Python, and others, and a WASM based virtual server (shell, filesystem, web server, etc..) Cost more but has better security for both the host and user.
Guess I was wrong about it costing more?
> … we can run PHP safely without the overhead of OS or hardware virtualization.
But it only runs at half the speed of PHP, so you need more resources.