laruence / yac

A fast, lock-free, shared memory user data cache for PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problems under high load

OlliL opened this issue · comments

Hi,

when I execute this script:
http://pastebin.com/tUYUnxef

with this Apache Bench command line options:

ab -H "Connection:close" -c 20 -n 500 http://www/test_yac.php

I get this result:

This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking ditta (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests


Server Software:        Apache/2.2.25
Server Hostname:        ditta
Server Port:            80

Document Path:          /test_yac.php
Document Length:        0 bytes

Concurrency Level:      20
Time taken for tests:   112.869 seconds
Complete requests:      500
Failed requests:        2
   (Connect: 0, Receive: 0, Length: 2, Exceptions: 0)
Write errors:           0
Total transferred:      116772 bytes
HTML transferred:       268 bytes
Requests per second:    4.43 [#/sec] (mean)
Time per request:       4514.759 [ms] (mean)
Time per request:       225.738 [ms] (mean, across all concurrent requests)
Transfer rate:          1.01 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1    3   1.5      3      28
Processing:  1756 4478 890.6   4436   10193
Waiting:     1756 4478 889.9   4436   10193
Total:       1758 4481 890.6   4438   10196

Percentage of the requests served within a certain time (ms)
  50%   4438
  66%   4685
  75%   4826
  80%   4937
  90%   5264
  95%   5808
  98%   6991
  99%   7489
 100%  10196 (longest request)

The errors are:
Warning: Yac::get(): Unserialization failed in /usr/local/www/data.default/test_yac.php on line 26
Warning: Yac::get(): Unserialization failed in /usr/local/www/data.default/test_yac.php on line 26

And this can be reproduced - you get always some erroneous responses

Hey, actually, this is expected behaviors, yac is a lockless cache, that is why it is so fast and also has some issues like this.

but this(the warnings you saw) also is a protection for preventing wrong data goes to user script.

to reduce this warnings: you need try to avoid or reduce the probability of multiple processes seting one key. increase the slots size, or you can increase the crc bytes(I will add a configuration in php.ini for this later).

thanks

Hi, as it is a warning - I wonder if I can catch it somehow and try to re-get the cache entry?

A "hack" that would allow you to catch the error is to set the error handler to a custom function that throws the error as an exception. Then directly after the cache get you can restore the error handler to it's previous function.

This will allow you to catch the warning like an exception and either retry or re-fetch it.