# ZTS - why are you using it?

- Thread: https://externals.io/message/65332
- Original archive: https://news-web.php.net/php.internals/65332
- Started by Zeev Suraski on 2013-01-29T09:03:51+00:00
- Messages: 54
- Page 1 of 3: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/65332.md?page=2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #65332 — Zeev Suraski — 2013-01-29T09:03:51+00:00

URL: https://externals.io/message/65332#65332

I didn’t want to hijack the Optimizer+ thread so I’m creating a new one,
based on the apparent level of interest in ZTS.  This isn’t an RFC to
remove ZTS by any stretch, but I **am** a bit confused about why people are
still using ZTS.



A bit of background.  I started the ZTS project (based on initial work by
Shane Caraveo more than a decade ago), and invested countless hours in
pushing it all throughout PHP.  So I really hold absolutely no grudge
against it, quite the contrary…  However, many years ago, I came to the
conclusion that it was a bit of a lost cause trying to weed out all the
thread safety issues from everywhere – and that a simpler, more elegant
solution exists in the form of FastCGI.



Which brings me to the subject of this mail – why are you using ZTS PHP
instead of single threaded PHP?  The reasons not to use it are few but
fairly major – it’s significantly slower than the non-ZTS PHP, and it’s
significantly less robust in the sense that a single bug somewhere can
bring down an entire server (or at least a bunch of many different
threads).  What are your reasons to choose it over FastCGI?



Zeev

---

## #65333 — netroby — 2013-01-29T09:11:58+00:00

URL: https://externals.io/message/65332#65333 · In reply to: #65332

> I didn’t want to hijack the Optimizer+ thread so I’m creating a new one,
> based on the apparent level of interest in ZTS.  This isn’t an RFC to
> remove ZTS by any stretch, but I **am** a bit confused about why people are
> still using ZTS.
>
>
>
> A bit of background.  I started the ZTS project (based on initial work by
> Shane Caraveo more than a decade ago), and invested countless hours in
> pushing it all throughout PHP.  So I really hold absolutely no grudge
> against it, quite the contrary…  However, many years ago, I came to the
> conclusion that it was a bit of a lost cause trying to weed out all the
> thread safety issues from everywhere – and that a simpler, more elegant
> solution exists in the form of FastCGI.
>
>
>
> Which brings me to the subject of this mail – why are you using ZTS PHP
> instead of single threaded PHP?  The reasons not to use it are few but
> fairly major – it’s significantly slower than the non-ZTS PHP, and it’s
> significantly less robust in the sense that a single bug somewhere can
> bring down an entire server (or at least a bunch of many different
> threads).  What are your reasons to choose it over FastCGI?
>
>
>
> Zeev
>
Old behavior not easily to be changed.
let it as it be, all of us like to keep on old behavior  as it was.

should put banner on php.net, say: do not using ZTS, that's old way.

-- 
Appreciate your time.
----------------------------
Netroby

---

## #65334 — Alexey Zakhlestin — 2013-01-29T09:25:54+00:00

URL: https://externals.io/message/65332#65334 · In reply to: #65332

> Which brings me to the subject of this mail – why are you using ZTS PHP
> instead of single threaded PHP?  The reasons not to use it are few but
> fairly major – it’s significantly slower than the non-ZTS PHP, and it’s
> significantly less robust in the sense that a single bug somewhere can
> bring down an entire server (or at least a bunch of many different
> threads).  What are your reasons to choose it over FastCGI?

I use it for long-running processes, when I need something like
http://pecl.php.net/package/pthreads
But, those are scenarios, when I don't need bytecode cache, because
everything is preloaded in "real" memory

--
Alexey Zakhlestin,
http://github.com/indeyets

---

## #65335 — Laruence — 2013-01-29T09:28:46+00:00

URL: https://externals.io/message/65332#65335 · In reply to: #65332

> I didn’t want to hijack the Optimizer+ thread so I’m creating a new one,
> based on the apparent level of interest in ZTS.  This isn’t an RFC to
> remove ZTS by any stretch, but I **am** a bit confused about why people are
> still using ZTS.
>
>
>
> A bit of background.  I started the ZTS project (based on initial work by
> Shane Caraveo more than a decade ago), and invested countless hours in
> pushing it all throughout PHP.  So I really hold absolutely no grudge
> against it, quite the contrary…  However, many years ago, I came to the
> conclusion that it was a bit of a lost cause trying to weed out all the
> thread safety issues from everywhere – and that a simpler, more elegant
> solution exists in the form of FastCGI.
>
>
>
> Which brings me to the subject of this mail – why are you using ZTS PHP
> instead of single threaded PHP?  The reasons not to use it are few but
> fairly major – it’s significantly slower than the non-ZTS PHP, and it’s
> significantly less robust in the sense that a single bug somewhere can
> bring down an entire server (or at least a bunch of many different
> threads).  What are your reasons to choose it over FastCGI?

Hey:

It's not we choose ZTS, it is there are many users run with them (IIS,
Apache+workers, and pthreads extension require it)

and all PHP extensions supports it, so if O+ doesn't, it feel a little
inconsistent.

thanks

>
>
>
> Zeev



-- 
Laruence  Xinchen Hui
http://www.laruence.com/

---

## #65336 — Laruence — 2013-01-29T09:31:43+00:00

URL: https://externals.io/message/65332#65336 · In reply to: #65335

> 
> > […]
>
> Hey:
>
> It's not we choose ZTS, it is there are many users run with them (IIS,
> Apache+workers, and pthreads extension require it)
>
> and all PHP extensions supports it, so if O+ doesn't, it feel a little
> inconsistent.

And,  if O+ aims only to be a PECL extension,  I think it's okey.

but if it is going to PHP src, I think the consistent should be
considered, agree?

thanks

>
> thanks
>
> > […]
>
>
>
> --
> Laruence  Xinchen Hui
> http://www.laruence.com/



-- 
Laruence  Xinchen Hui
http://www.laruence.com/

---

## #65337 — Zeev Suraski — 2013-01-29T09:35:35+00:00

URL: https://externals.io/message/65332#65337 · In reply to: #65335

> Hey:
>
> It's not we choose ZTS, it is there are many users run with them (IIS,
> Apache+workers, and pthreads extension require it)

For pthreads I can understand it, but why would users be using it on
IIS/Apache instead of using FastCGI?  FastCGI is both faster and more
robust.  Is it a matter of lack of knowledge, or is there a real reason to
use it?

> and all PHP extensions supports it, so if O+ doesn't, it feel a little
> inconsistent.

My question was outside the context of O+ - it should support it for as long
as ZTS is available...

Zeev

---

## #65338 — Laruence — 2013-01-29T09:38:28+00:00

URL: https://externals.io/message/65332#65338 · In reply to: #65337

> > […]
>
> For pthreads I can understand it, but why would users be using it on
> IIS/Apache instead of using FastCGI?  FastCGI is both faster and more
> robust.  Is it a matter of lack of knowledge, or is there a real reason to
> use it?
>
> > […]
>
> My question was outside the context of O+ - it should support it for as long
> as ZTS is available...

Oh, in that case,  I prefer fcgi(eg: nginx fpm) too.  :)

thanks
>
> Zeev



-- 
Laruence  Xinchen Hui
http://www.laruence.com/

---

## #65341 — Pierre Joye — 2013-01-29T09:56:16+00:00

URL: https://externals.io/message/65332#65341 · In reply to: #65332

hi Zeev,




> Which brings me to the subject of this mail – why are you using ZTS PHP
> instead of single threaded PHP?  The reasons not to use it are few but
> fairly major – it’s significantly slower than the non-ZTS PHP, and it’s
> significantly less robust in the sense that a single bug somewhere can
> bring down an entire server (or at least a bunch of many different
> threads).  What are your reasons to choose it over FastCGI?

There are situations where FPM/FCGI are not appropriate, or the server
used does not support NTS (Apache windows for example, when fcgi is
not an option).

However, in the long run, I would like to kill TSRM altogether, moving
the file/IO related parts where they should be implemented, either the
engine or main. Does it mean we will kill thread safety by doing so?
No. My idea is to replace it with LTS (thread local storage) which
drastically reduce the thread safety issues due to its exact nature,
store local thread data per thread and not per process. Issues include
well know crashes due to non thread safe code (almost none left in
core, but some libs have issues) and brings a huge performance
improvement.

The other main reason from my side to keep ZTS is Windows. Windows
cannot perform well using process based SAPI. It won't match linux as
long as it runs within a webserver using a process based
implementation (but CLI does not match linux performance and is even
faster in a couple of use cases). I've made some tests to write new
ISAPIs for IIS8 and with the httpkernel (1). The performance are very
promising, given that it is still only a proof of concepts. Having an
ISAPI also allows a tighter integration to IIS8 (pipelines, auths,
scripting, etc.), which is not possible to do now using fastcgi (no
direct access but using RMI or the IIS shell, but horrible, in all
possible ways).

Conclusion:

Yes, TSRM is horrible and does not match modern thread safe
implementation (APC does it better for its usage f.e. using rwlock).
However it would be a very bad idea to give up on thread safety only
because the relatively new trend is all about single threaded/process
based implementation. These systems have limits and I'm sure we will
see some big change in this area in the couple of years. TLS will let
us to do the transition and we can 'easily' support extension
developers to port their extensions.

(1) similar to our builtin webserver except that it can be used in
production servers. It is what IIS used under the hood. Having a SAPI
relying directly on HttpKernel will allow one to create many app pools
using PHP only. It will work smoothly even if IIS runs on the same
host, sharing the same IPs or ports, even the cache will work.

Cheers.
--
Pierre

@pierrejoye

---

## #65344 — Pierre Joye — 2013-01-29T10:06:46+00:00

URL: https://externals.io/message/65332#65344 · In reply to: #65341

> The other main reason from my side to keep ZTS is Windows. Windows
> cannot perform well using process based SAPI. It won't match linux as
> long as it runs within a webserver using a process based
> implementation (but CLI does not match linux performance and is even
> faster in a couple of use cases).

I mean:

but CLI does match linux performance and is even faster in a couple of
use cases :)


--
Pierre

@pierrejoye

---

## #65348 — johannes@schlueters.de — 2013-01-29T11:05:43+00:00

URL: https://externals.io/message/65332#65348 · In reply to: #65332

> I didn’t want to hijack the Optimizer+ thread so I’m creating a new one,
> based on the apparent level of interest in ZTS.  This isn’t an RFC to
> remove ZTS by any stretch, but I **am** a bit confused about why people are
> still using ZTS.

I doubt many people use it in production, especially under "high" load.
About a year ago I've spent quite some time fixing threading issues in
different parts of PHP (object instantiation in the engine, mysqli, ...)
there were a few bug reports but considering how simple it was to
exploit some of the bugs (<?php new stdclass; ?>, or any other internal
class, was all that was needed for one of the bugs) there were way too
few reports.

johannes

---

## #65350 — Zeev Suraski — 2013-01-29T11:10:09+00:00

URL: https://externals.io/message/65332#65350 · In reply to: #65341

> The other main reason from my side to keep ZTS is Windows. Windows
cannot
> perform well using process based SAPI.

Windows actually works quite well with FastCGI.  So well Microsoft even
created their own version for IIS.  It's outperforming the ISAPI module by
a wide margin.

Other than Apache/Windows not having FastCGI support(*), I really can't
imagine any situation where using ZTS inside of a Web Server context makes
any sense at all.  I wouldn't call it a new trend, it's both old (I've
been pushing for it since at least 2006, probably earlier) and with very
solid technical reasons (faster, more reliable).

> Yes, TSRM is horrible and does not match modern thread safe
implementation
> (APC does it better for its usage f.e. using rwlock).

Note that I wasn't talking about the implementation of ZTS, but why you
would want to use it in the first place.  I actually think that using
thread local storage is much better than using locks - but if you can make
the whole problem disappear because there's no need for thread safety,
that's even better.  Why heavily invest in something unless there's a very
good reason to use it?

Zeev

(*) Apache actually does have a good FastCGI implementation available in
Zend Server for Windows (including the free CE version).  Using it is
faster and more reliable than using mod_php on Windows.

---

## #65351 — johannes@schlueters.de — 2013-01-29T11:15:22+00:00

URL: https://externals.io/message/65332#65351 · In reply to: #65348

> exploit some of the bugs (<?php new stdclass; ?>, or any other internal
> class, was all that was needed for one of the bugs) there were way too
> few reports.

Ah, that specific bug was 5.4-only, back then 5.4 was quite new. But
there were other bugs, too.

johannes

---

## #65352 — Pierre Joye — 2013-01-29T11:15:53+00:00

URL: https://externals.io/message/65332#65352 · In reply to: #65350

>
> > […]
> cannot
> > […]
>
> Windows actually works quite well with FastCGI.  So well Microsoft even
> created their own version for IIS.  It's outperforming the ISAPI module by
> a wide margin.

Laziness and design mistake. Everything on windows (AD,IIS, asp.net, etc)
uses thread.

And no, nuts is not faster. I am not talking about PHP zts, but in general.

> Other than Apache/Windows not having FastCGI support(*), I really can't
> imagine any situation where using ZTS inside of a Web Server context makes
> any sense at all.  I wouldn't call it a new trend, it's both old (I've
> been pushing for it since at least 2006, probably earlier) and with very
> solid technical reasons (faster, more reliable).

Miss the rest of my mail or? Current implementation is outdated and slow.

> > […]
> implementation
> > […]
>
> Note that I wasn't talking about the implementation of ZTS, but why you
> would want to use it in the first place.  I actually think that using
> thread local storage is much better than using locks - but if you can make
> the whole problem disappear because there's no need for thread safety,
> that's even better.  Why heavily invest in something unless there's a very
> good reason to use it?

See what I wrote in my previous reply.

Cheers,

---

## #65355 — Martin Keckeis — 2013-01-29T11:28:35+00:00

URL: https://externals.io/message/65332#65355 · In reply to: #65350

> (*) Apache actually does have a good FastCGI implementation available in
> Zend Server for Windows (including the free CE version).  Using it is
> faster and more reliable than using mod_php on Windows.


Absolute right. Zend Server works great on Windows with FastCGI.
Using it since 3 years and got never problems.

---

## #65359 — johannes@schlueters.de — 2013-01-29T11:45:21+00:00

URL: https://externals.io/message/65332#65359 · In reply to: #65352

> 
> Laziness and design mistake. Everything on windows (AD,IIS, asp.net,
> etc)
> uses thread.

Well, most other things don't create "shared-nothing" environments like
PHP does. ASP, not only due to the Application object, for instance
isn't shared-nothing like PHP but sharing state. So what we're doing,
basically, is emulate a separation of threads, similar to what an
operating system should do with processes.

Of course an opcode cache isn't shred-nothing either, and maybe sharing
opcodes within a process is faster than doing this in shared memory. 
> 
> Miss the rest of my mail or? Current implementation is outdated and
> slow.

That is true. Many modern compilers and environments provide  better
support for thread local storages ....


What I see is that TSRM brings a lot of complexity and introduces risk
of bugs in there as many developers don't think about. Most of us are
focused on the nice and simple world of single-threaded computing. And I
assume that we can still find quite some threading bugs when going on a
hunt for them ... so besides of pure executable performance there is
also the cost of developer power for (proper) maintenance ...

johannes

---

## #65361 — Pierre Joye — 2013-01-29T11:49:11+00:00

URL: https://externals.io/message/65332#65361 · In reply to: #65359

hi,

On Tue, Jan 29, 2013 at 12:45 PM, Johannes Schlüter
<johannes@schlueters.de> wrote:
> 
> > […]
>
> Well, most other things don't create "shared-nothing" environments like
> PHP does. ASP, not only due to the Application object, for instance
> isn't shared-nothing like PHP but sharing state. So what we're doing,
> basically, is emulate a separation of threads, similar to what an
> operating system should do with processes.
>
> Of course an opcode cache isn't shred-nothing either, and maybe sharing
> opcodes within a process is faster than doing this in shared memory.

It is inter process sharing and is very expensive, nothing to compare
with shared memory within a single process, accross many threads.

> > […]
>
> That is true. Many modern compilers and environments provide  better
> support for thread local storages ....

Exactly, or more exactly CRTs (libc, crt and the likes)>

> What I see is that TSRM brings a lot of complexity and introduces risk
> of bugs in there as many developers don't think about. Most of us are
> focused on the nice and simple world of single-threaded computing. And I
> assume that we can still find quite some threading bugs when going on a
> hunt for them ... so besides of pure executable performance there is
> also the cost of developer power for (proper) maintenance ...

The amount of bugs is rather low. We do test in TS and TS on a daily
basis. The last extension causing more critical issues was mysql, we
have discussed these bugs for a long time.


However let me state my point clear: Giving up on thread safety would
be a mistake as big as safemode and other insane choices we made. That
does mean we have to keep going with the current state but we must
keep it. Other languages support it because most of them are thread
safe by design and allows extensions to rely on that.

Cheers,
--
Pierre

@pierrejoye

---

## #65362 — Pierre Joye — 2013-01-29T11:56:45+00:00

URL: https://externals.io/message/65332#65362

> > […]
>
>
> Of course everything that is Windows native uses threads, but I don't
> believe any language that is single-threaded on other platforms - has a
> thread safe version for Windows.

Python, for example, is thread safe by default. Extensions developers
can rely on its APIs to write TS code. Our core is designed in a way
that it is painful to have to deal with two code bases. That's what
causes troubles, not really something else.

> I disagree that laziness and design mistakes are what makes ZTS slower.
> It's slower by design, since instead of relying on operating system
> isolation - you have to emulate it yourself in userland code.

It was and still is a lazy and design mistake to have focused on
FastCGI to support PHP on IIS more easily, while everything else in
this stack uses what the whole OS stack does.


> Contrary to popular belief FastCGI actually works very very well on Windows,
> and has substantial advantages over using a server module - even on Linux
> (it's no coincidence that there are hoards of users migrating from Apache to
> nginx, where a server module isn't even an option - and they're seeing
> better performance, not worse).

I never said that FastCGI does not work well. But that doing so will
never allow us to reach the performance we could get using a more
suited implementation.

About nginx vs Apache, I'm also quite sure that we can get an Apache
SAPI module performing as good as nging with FPM. It is only almost
impossible with the current implementation of PHP, we both know that.
We have seen examples in the past already where well optimized php and
apache were as fast as lighttpd (back then) with a correct setup.

Again, giving up on thread safety is a major mistake.

Cheers,
--
Pierre

@pierrejoye

---

## #65363 — johannes@schlueters.de — 2013-01-29T12:01:20+00:00

URL: https://externals.io/message/65332#65363 · In reply to: #65361

> > […]
> 
> Exactly, or more exactly CRTs (libc, crt and the likes)>

That's what I called "environment" - some of these things depend on
kernels, some on libraries, ... anyway - irrelevant terminology :-p

> > […]
> 
> The amount of bugs is rather low. We do test in TS and TS on a daily
> basis. The last extension causing more critical issues was mysql, we
> have discussed these bugs for a long time.

There were mysqli threading bugs, the last one of those actually had
been engine bugs which affected other extensions, too. See i.e.
http://news.php.net/php.internals/59353

Such bugs identified a year after the release of 5.4 gives me quite a
good indication of the little actual testing being done overall.

johannes

---

## #65364 — Zeev Suraski — 2013-01-29T12:06:39+00:00

URL: https://externals.io/message/65332#65364 · In reply to: #65361

> -----Original Message-----
> From: Pierre Joye [mailto:pierre.php@gmail.com]
> Sent: Tuesday, January 29, 2013 1:49 PM
> To: Johannes Schlüter
> Cc: Zeev Suraski; PHP internals
> Subject: Re: [PHP-DEV] ZTS - why are you using it?
>
> On Tue, Jan 29, 2013 at 12:45 PM, Johannes Schlüter
> <johannes@schlueters.de> wrote:
> > […]
memory.
>
> It is inter process sharing and is very expensive, nothing to compare
with shared
> memory within a single process, accross many threads.

What are you basing that assertion on?  Shared memory should have
identical performance to regular process memory.  It's mapped in very
similar way.

There are effectively no performance advantages to using multiple threads
over multiple processes, none whatsoever.  It might help you a bit with
memory consumption - but in the case of PHP, FastCGI with it's n:m mapping
is much superior to it.

Using multiple threads only makes sense if you take functional advantage
of that, like shared objects and such - which we don't.

> > […]
>
> Exactly, or more exactly CRTs (libc, crt and the likes)>

Can we stop arguing about the implementation - which I didn't even bring
up in my original mail - and focus on the original question - why would
you want thread safe PHP in the first place?
So far the only real use case that was brought up was for using pthreads
in a long-running app.  I've yet to hear about a single real reason of why
someone would want to use it in web server context that is not based on
misconceptions or myths.

 > However let me state my point clear: Giving up on thread safety would
be a
> mistake as big as safemode and other insane choices we made.

As big as giving up on safe mode or creating it in the first place?  If
it's the former, I say let's do it right now :)

Zeev

---

## #65365 — Zeev Suraski — 2013-01-29T12:08:33+00:00

URL: https://externals.io/message/65332#65365

>
>
> 
> > […]
>
> Laziness and design mistake. Everything on windows (AD,IIS, asp.net, etc) uses thread.
>
> And no, nuts is not faster. I am not talking about PHP zts, but in general.


Of course everything that is Windows native uses threads, but I don't
believe any language that is single-threaded on other platforms - has
a thread safe version for Windows.

I disagree that laziness and design mistakes are what makes ZTS
slower.  It's slower by design, since instead of relying on operating
system isolation - you have to emulate it yourself in userland code.

Contrary to popular belief FastCGI actually works very very well on
Windows, and has substantial advantages over using a server module -
even on Linux (it's no coincidence that there are hoards of users
migrating from Apache to nginx, where a server module isn't even an
option - and they're seeing better performance, not worse).

>
> > […]
>
> Miss the rest of my mail or? Current implementation is outdated and slow.


How does it relate to what I said?
Regardless, a new implementation of ZTS will not change the
fundamentals. We're unlikely to ever achieve single-threaded
performance or reach the same level of stability with ZTS.  With a
system like PHP that is all about concurrency of stateless,
independent requests - I don't think we're going to reach any
meaningful limits any time soon.

FastCGI has another huge advantage, in that it breaks the 1:1 linkage
between a 'processing unit' (a web server process or thread) and a PHP
instance, and makes it an n:m mapping - in that you could have a lot
more web server processing units than you would need PHP instances.
That's one of the key reasons you can achieve better performance /
density with PHP on nginx than you can with Apache.  The same would
apply to IIS - ISAPI vs. FastCGI.

Zeev

---

## #65366 — Pierre Joye — 2013-01-29T12:13:05+00:00

URL: https://externals.io/message/65332#65366 · In reply to: #65363

On Tue, Jan 29, 2013 at 1:01 PM, Johannes Schlüter
<johannes@schlueters.de> wrote:

> There were mysqli threading bugs, the last one of those actually had
> been engine bugs which affected other extensions, too. See i.e.
> http://news.php.net/php.internals/59353
>
> Such bugs identified a year after the release of 5.4 gives me quite a
> good indication of the little actual testing being done overall.

Can you stay fair, check your backlog and the verbose mail exchanges
we had with the mysql connectivity team about these issues? Before and
after the bugs were reported? thanks.

--
Pierre

@pierrejoye

---

## #65367 — Pierre Joye — 2013-01-29T12:18:43+00:00

URL: https://externals.io/message/65332#65367 · In reply to: #65364

> > […]
> with shared
> > […]
>
> What are you basing that assertion on?  Shared memory should have
> identical performance to regular process memory.  It's mapped in very
> similar way.
>
> There are effectively no performance advantages to using multiple threads
> over multiple processes, none whatsoever.  It might help you a bit with
> memory consumption - but in the case of PHP, FastCGI with it's n:m mapping
> is much superior to it.
>
> Using multiple threads only makes sense if you take functional advantage
> of that, like shared objects and such - which we don't.

Testing maybe?

> > […]
>
> Can we stop arguing about the implementation

No, we can't. The main reason of the bugs and performance issue is due
to the current implementation and how extensions developers have to
deal with it. It is not separable from discussing what could be the
worst decision we ever made, droping thread safety.

> - which I didn't even bring
> up in my original mail - and focus on the original question - why would
> you want thread safe PHP in the first place?

I mentioned one which is alone a good enough reason. LTS brings zts in
line with NTS in term of performance while reducing massively the
shared/locks access related bugs for many areas.

> So far the only real use case that was brought up was for using pthreads
> in a long-running app.  I've yet to hear about a single real reason of why
> someone would want to use it in web server context that is not based on
> misconceptions or myths.

Thanks, it is really nice to say something and being told that what
has been done is misconceptions or myths, especially if you gave up on
thread safety years ago within your company. That's all good, as long
as it only affects your company products and not PHP as a whole.


> > […]
> be a
> > […]
>
> As big as giving up on safe mode or creating it in the first place?  If
> it's the former, I say let's do it right now :)

both :) But with a small difference, back then TSRM was not bad. But
it was never updated to what is available now on any modern OS.

Cheers,
--
Pierre

@pierrejoye

---

## #65369 — Zeev Suraski — 2013-01-29T12:52:34+00:00

URL: https://externals.io/message/65332#65369 · In reply to: #65367

> -----Original Message-----
> From: Pierre Joye [mailto:pierre.php@gmail.com]
> Sent: Tuesday, January 29, 2013 2:19 PM
> To: Zeev Suraski
> Cc: Johannes Schlüter; PHP internals
> Subject: Re: [PHP-DEV] ZTS - why are you using it?
>
> 
>
> > […]
>
> Testing maybe?

Retest then, you've got it wrong.  Shared memory (or memory mapped files
as they'd be on Windows) are simply memory, it's available to the process
in exactly the same way and while the OS does slightly different
book-keeping for it in how it populates the pages - it's negligible.

> > […]
>
> No, we can't. The main reason of the bugs and performance issue is due
to the
> current implementation and how extensions developers have to deal with
it. It is
> not separable from discussing what could be the worst decision we ever
made,
> droping thread safety.

Well, I'm not interested in discussing the implementation when the need
isn't clear to me.
For example, you could say that thread-safe PHP would be 2x faster.  Or 2x
more memory efficient.  Or will enable us to do XYZ which we otherwise
can't.
For now, an *utopian* ZTS mode would, at best, not give us anything.
Even if we put aside the performance/reliability issues - why would
someone want that mode over other modes?

> > […]
>
> Thanks, it is really nice to say something and being told that what has
been done
> is misconceptions or myths, especially if you gave up on thread safety
years ago
> within your company. That's all good, as long as it only affects your
company
> products and not PHP as a whole.

Pierre, I'm sorry, but when you state something like '[shared memory] is
inter process sharing and is very expensive', there's no other way to
describe it other than a myth.  Better theoretical performance is a
misconception.  The best PHP performance/density available today is on
nginx, which couldn't be farther away from
multithreaded-PHP-in-process-arch.

Even after what you just said, you've yet to bring up a single reason for
why one would want to use ZTS inside a web server context.  You seem to
love ZTS with a vengeance but you can't quite explain why.  My 'company'
didn't decide anything regarding ZTS.  It was me, probably the person with
the most experience with ZTS back in the day, and it was probably much
more difficult for me than anybody else to realize that the ZTS approach
was the wrong path to go to as it was my baby project.

BTW, for the love of [insert here], I'm not talking about killing thread
safety.  It's useful for long running processes, and who knows, maybe in
the future we'll have threads inside PHP.  But I *am* talking about
telling people that using ZTS in production is not recommended and that
they should be using FastCGI instead.

Zeev

---

## #65373 — damian@tylczynski.pl — 2013-01-29T13:01:45+00:00

URL: https://externals.io/message/65332#65373 · In reply to: #65369

As a developer I really enjoyed that discussion, it was very
informative for me. I'm always stuck with question which version of
PHP to use.

2013/1/29 Zeev Suraski <zeev@zend.com>:
> > […]
>
> Retest then, you've got it wrong.  Shared memory (or memory mapped files
> as they'd be on Windows) are simply memory, it's available to the process
> in exactly the same way and while the OS does slightly different
> book-keeping for it in how it populates the pages - it's negligible.
>
> > […]
> to the
> > […]
> it. It is
> > […]
> made,
> > […]
>
> Well, I'm not interested in discussing the implementation when the need
> isn't clear to me.
> For example, you could say that thread-safe PHP would be 2x faster.  Or 2x
> more memory efficient.  Or will enable us to do XYZ which we otherwise
> can't.
> For now, an *utopian* ZTS mode would, at best, not give us anything.
> Even if we put aside the performance/reliability issues - why would
> someone want that mode over other modes?
>
> > […]
> been done
> > […]
> years ago
> > […]
> company
> > […]
>
> Pierre, I'm sorry, but when you state something like '[shared memory] is
> inter process sharing and is very expensive', there's no other way to
> describe it other than a myth.  Better theoretical performance is a
> misconception.  The best PHP performance/density available today is on
> nginx, which couldn't be farther away from
> multithreaded-PHP-in-process-arch.
>
> Even after what you just said, you've yet to bring up a single reason for
> why one would want to use ZTS inside a web server context.  You seem to
> love ZTS with a vengeance but you can't quite explain why.  My 'company'
> didn't decide anything regarding ZTS.  It was me, probably the person with
> the most experience with ZTS back in the day, and it was probably much
> more difficult for me than anybody else to realize that the ZTS approach
> was the wrong path to go to as it was my baby project.
>
> BTW, for the love of [insert here], I'm not talking about killing thread
> safety.  It's useful for long running processes, and who knows, maybe in
> the future we'll have threads inside PHP.  But I *am* talking about
> telling people that using ZTS in production is not recommended and that
> they should be using FastCGI instead.
>
> Zeev
>
> --
> 
> 
>



-- 
Pozdrawiam,
Damian Tylczyński

---

## #65375 — Pierre Joye — 2013-01-29T13:18:35+00:00

URL: https://externals.io/message/65332#65375 · In reply to: #65369

> > […]
>
> Retest then, you've got it wrong.  Shared memory (or memory mapped files
> as they'd be on Windows) are simply memory, it's available to the process
> in exactly the same way and while the OS does slightly different
> book-keeping for it in how it populates the pages - it's negligible.

It is not negligible, also the locking is different. Also, if I
remember correctly there is no rwlock support either, which is a huge
cons.

> > […]
> to the
> > […]
> it. It is
> > […]
> made,
> > […]
>
> Well, I'm not interested in discussing the implementation when the need
> isn't clear to me.

> For example, you could say that thread-safe PHP would be 2x faster.  Or 2x
> more memory efficient.  Or will enable us to do XYZ which we otherwise
> can't.

There are quite a few things I can do on Windows only in thread safe
environments (f.e. ESENT, builtin DB, used by AD for example, damned
fast).

> For now, an *utopian* ZTS mode would, at best, not give us anything.
> Even if we put aside the performance/reliability issues - why would
> someone want that mode over other modes?

I must be really unclear or something along this line. Alone on IIS,
there are dozen of features you can't do nor use using fastcgi. Apache
could also be used in a better way (windows here too, linux has a
module for both builds of apache).

btw, have you tried to compare IIS/FastCGI (I won't even try with
apache+fastcgi) on Windows vs nginx-fpm on linux? I would be very
surprised if your numbers show that they are equivalent.

> Pierre, I'm sorry, but when you state something like '[shared memory] is
> inter process sharing and is very expensive', there's no other way to
> describe it other than a myth.  Better theoretical performance is a
> misconception.  The best PHP performance/density available today is on
> nginx, which couldn't be farther away from
> multithreaded-PHP-in-process-arch.
>
> Even after what you just said, you've yet to bring up a single reason for
> why one would want to use ZTS inside a web server context.  You seem to
> love ZTS with a vengeance but you can't quite explain why.  My 'company'
> didn't decide anything regarding ZTS.  It was me, probably the person with
> the most experience with ZTS back in the day, and it was probably much
> more difficult for me than anybody else to realize that the ZTS approach
> was the wrong path to go to as it was my baby project.

It could have been the wrong path for some situation back then, but it
is definitively not wrong to improve thread safety.

I would rather have one single build instead, and enable the ts
related stuff when necessary. It will add some more functions in the
engine but it would be much more clear and easier than what we have
now.

> BTW, for the love of [insert here], I'm not talking about killing thread
> safety.

That's how it looks and that's where this discussion is going, tbh.

> It's useful for long running processes, and who knows, maybe in
> the future we'll have threads inside PHP.  But I *am* talking about
> telling people that using ZTS in production is not recommended and that
> they should be using FastCGI instead.

As far as I remember, we already do that for a couple of web servers.
And in the long run, I will rather tell not to use FastCGI for
dedicated hosting and the likes. That being said, I also met many ISPs
which are not happy with the all-fastcgi, memory usageand performance
were the issues (have to read my backlog for other details :).

Cheers,
--
Pierre

@pierrejoye

---

Next page: https://externals.io/message/65332.md?page=2
