5 ms·
Except PHP is not Java, and it never can be. What is PHP's multithreading model again? Hotspot VM? NIO? I'm sure someone will chime in and cite something simi
by codesushi42 7y ago
Except PHP is not Java, and it never can be.
What is PHP's multithreading model again? Hotspot VM? NIO?
I'm sure someone will chime in and cite something similar in PHP, but the comparison will be laughable in reality.
- gremlinsinc 7y agoI'm not a concurrency expert (haven't had to do much high-performance stuff), but php does have coroutines like go's --if you use swoole, the performance is actually higher than node in some benchmarks and other multi-threaded / parallel programming paradigms, which comforts me to know that if I have the use case it's there, so I don't necessarily need to drop everything and pick up rust or java or go or another language w/ native concurrency models. Not saying php is better, there's definitely reasons using rust, elixir, et al would be a better decision for scalability/etc... Just saying it isn't as far off from java, and it's getting JIT I believe in 8.0 (tentatively), whether that improves speed/proficiency is yet to be determined. That said, I've been a laravel dev since 2013, getting a little bored, so have been branching out and toying w/ other things like clojure, elixir, rust, and node.js for backends to web/mobile apps. Though, laravel is easiest/fastest most of the time to get a project completed by myself.
- codesushi42 7y agoCoroutines do not mean that you get parallel execution. Concurrency is not the same as parallelization. If PHP does not have JIT, then it's nowhere near the speed of Java. Even if it did, Java would likely beat it significantly. I would encourage you to read about Java's Hotspot VM and its adaptive optimizations.
- kamranjon 7y agoMultithreading is not strictly parallelism, typical discussions of multithreading regard concurrency, and multithreading is what you initially asked about. PHP 7.4 will ship with a JIT as an experimental feature and PHP 8 will ship with it built in standard.
- codesushi42 7y agoMultithreading in Java means parallelism, which is what I was originally asking about. You're confused. Nowhere did I claim that multithreading always means parrelalism.
- cutler 7y agoIn my experience Clojure with Luminus is the quickest for getting something up and running. No brittle ORM to deal with - just HugSQL for turning raw SQL into functions.
- bernawil 7y ago>What is PHP's multithreading model again Since it's inception, the PHP implementation hasn't been threadsafe and since, the way of doing paralellism has been process forking. Later iterations where released with support for long-lived processes and threads but it's still not officially "stable" since again, historically the model of process forking made the ecosystem take for granted non-memory safety. On the other hand, at least since the last time I was doing Java, paralellism is done via multithreading. Sure, there must be someone doing some else out there, but relevant frameworks like Spring work by making 1 thread by http request. IMHO the right way of dealing with concurrency is the Node way. But comparing the PHP vs Java y think the PHP way is better. In small-medium scale the Java way is obviously more performant. The problem is when you scale to more instances. The PHP way of immutable processes really makes vertical scalling easier.
- codesushi42 7y agoPHP scales better than Java? Java is only suited for small to medium scale? That's absurd and you are completely wrong. Java web servers are multithreaded. Java has JIT. Java has a Hotspot VM with JIT optimizations at runtime. This is why companies like Google and Amazon run their stacks on Java. It scales. Facebook had to write their own fork of PHP due to performance issues.
- bernawil 7y ago>Java is only suited for small to medium scale? Never said that. What I said was that in the small to medium scale Java was obviously more performant because of the persistent instance & multithreaded model. But beyond that it really is no longer true. The immutable "shared nothing" process forking model of PHP scales horizontally very easily. >Java web servers are multithreaded this really is a disadvantage when scalling. The default linux thread stack is 1024k for 64-bit VMs, can't find what's the minium if you tweak it enough. You can see how bad that scalles to thousands of concurrent requests. And then there's containerization and microservices, where each instance needs a full JVM. >This is why companies like Google and Amazon run their stacks on Java You can make anything scale with Google or Amazon budgets. Again, just listing some pros and cons of both approaches, both of which I think are not even the best.