Is Zend_Log reliable when multiple user writing to the same file?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Is Zend_Log reliable when multiple user writing to the same file?

howard chen
Just wonder if the Zend_Log when writing to local file, is it reliable
when multiple user writing to the same file?

What will happen if other is writing?
Reply | Threaded
Open this post in threaded view
|

Re: Is Zend_Log reliable when multiple user writing to the same file?

weierophinney
Administrator
-- howard chen <[hidden email]> wrote
(on Sunday, 21 March 2010, 12:33 AM +0800):
> Just wonder if the Zend_Log when writing to local file, is it reliable
> when multiple user writing to the same file?
>
> What will happen if other is writing?

It should be safe; it uses file locking internally to prevent issues
with concurrent writers.

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
Reply | Threaded
Open this post in threaded view
|

Re: Is Zend_Log reliable when multiple user writing to the same file?

howard chen
Hi,

On Sun, Mar 21, 2010 at 12:49 AM, Matthew Weier O'Phinney
<[hidden email]> wrote:

> It should be safe; it uses file locking internally to prevent issues
> with concurrent writers.
>
> --


Thanks for your reply.

What if a file is being locked by an apache process? Exception anyway
or will wait?

I want log can be 100% write into the log file, so file based log is
not possible?

Or should I use syslog?
Reply | Threaded
Open this post in threaded view
|

Re: Is Zend_Log reliable when multiple user writing to the same file?

till
On Sat, Mar 20, 2010 at 7:40 PM, howard chen <[hidden email]> wrote:

> Hi,
>
> On Sun, Mar 21, 2010 at 12:49 AM, Matthew Weier O'Phinney
> <[hidden email]> wrote:
>
>> It should be safe; it uses file locking internally to prevent issues
>> with concurrent writers.
>>
>> --
>
>
> Thanks for your reply.
>
> What if a file is being locked by an apache process? Exception anyway
> or will wait?
>
> I want log can be 100% write into the log file, so file based log is
> not possible?
>
> Or should I use syslog?
>

If performance is a concern, avoid doing logs (in production). :-)

We are using Zend_Log+syslog (there's a writer for it) for all our
CLI-tools. No idea what kind of logging you are after.

Till
Reply | Threaded
Open this post in threaded view
|

Re: Is Zend_Log reliable when multiple user writing to the same file?

howard chen
On Sun, Mar 21, 2010 at 8:13 AM, till <[hidden email]> wrote:
> If performance is a concern, avoid doing logs (in production). :-)
>
> We are using Zend_Log+syslog (there's a writer for it) for all our
> CLI-tools. No idea what kind of logging you are after.
>
> Till
>

What I concern is potential loss of log due to locking. (Assume
multiple apache processes are running)
Reply | Threaded
Open this post in threaded view
|

Re: Is Zend_Log reliable when multiple user writing to the same file?

Guillaume Rossolini

On Sun, Mar 21, 2010 at 3:42 AM, howard chen <[hidden email]> wrote:

What I concern is potential loss of log due to locking. (Assume
multiple apache processes are running)

Hi,

You needn't be concerned, as Zend_Log uses system-level file locking.  And as you know, the OS is above apache ;)
That means that multiple simultaneous Zend_Log instances do not immediately write or fail, they wait in a queue until they manage to write or until their timeout happens.

Regards,

--
Guillaume Rossolini
Reply | Threaded
Open this post in threaded view
|

RE: Is Zend_Log reliable when multiple user writing to the same file?

Thomas D.
Hi,

Guillaume Rossolini wrote:
> You needn't be concerned, as Zend_Log uses system-level
> file locking.  And as you know, the OS is above apache ;)
> That means that multiple simultaneous Zend_Log instances
> do not immediately write or fail, they wait in a queue until
> they manage to write or until their timeout happens.

The last part is important.

We don't know what your script is doing next to your logging.
We don't know what you are logging.
We don't know other I/O operations, the system the application is served
from is doing.

So the only problem you could run in would be a script execution timeout,
because the script is still waiting to be able to write to that log file,
which is currently locked by other instances.

What you can do:
1) Benchmark your system. Write a script which will write to a log file and
run it as much as you can. It will show you, how many parallel calls your
system is able to serve. Then you could limit your apache to that number...


2) Try to delay your logging. Maybe you can use Zend Job Queue/Zend_Queue.


3) Use another writer, which is optimized for high performance logging (keep
in mind that logging to a file isn't really fast, because on every call you
first lock the file, open it, write to it, close the file and finally unlock
it. A writer like syslog keeps the log file opened for example).


--
Regards,
Thomas


Regards,
Thomas