php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58215 APC takes too long to free memory
Submitted: 2008-06-03 14:56 UTC Modified: 2008-08-12 10:49 UTC
From: gdiego at gmail dot com Assigned:
Status: Closed Package: APC (PECL)
PHP Version: 5.2.5 OS: Debian
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: gdiego at gmail dot com
New email:
PHP Version: OS:

 

 [2008-06-03 14:56 UTC] gdiego at gmail dot com
Description:
------------
When calling apc_store, if it needs memory, it might take a long time to free if several user variables are stored.

I think the problem comes with a modification at line 659 / 660 of php_apc.c that now has this code:

 apc_cache_expunge(apc_cache,t);
 apc_cache_expunge(apc_user_cache,t);

If several variables are stored in the cache then it takes a long time to free some.

Reproduce code:
---------------
<?
  set_time_limit(0);
  for ($i = 0; $i < 500000; $i++) {
    $u = apc_cache_info("user", true); $u = $u['mem_size'];
    if ($i % 50000 == 0) echo "--- $i $u\n";
    $x = microtime(true); apc_store($i, $i); $x = microtime(true) - $x;
    if ($x > 3) die("$x seconds taken for $i\n");
  }
  echo "test";
?>


Expected result:
----------------
An echo every time $i % 50000 == 0
test


Actual result:
--------------
--- 0 0
--- 50000 5177780
--- 100000 10377780
--- 150000 15677780
76.2400200367 seconds taken for 163626

(it takes a long time at iteration 163626 when cache is full)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-26 08:11 UTC] gopalv82 at yahoo dot com
With apc-3.1.x CVS HEAD, with a slight change to your script

    $u = apc_cache_info("user", true); $e = $u['expunges']; $m = $u['mem_size'];
    if ($i % 50000 == 0) echo "--- $i $e $m\n";

--- 0 0 0
--- 50000 0 28000000
--- 100000 1 27072080
--- 150000 2 26144160
--- 200000 3 25216240
--- 250000 4 24288320
--- 300000 5 23360400
--- 350000 6 22432480
--- 400000 7 21504560
--- 450000 8 20576640

took 14 seconds with a 32Mb cache. Please test CVS HEAD of pecl/apc and update the bug
 [2008-06-26 09:18 UTC] gdiego at gmail dot com
Hi there,

even if it takes 14 seconds now, remember it's a php script (timeout: 30 seconds). What happens if you are using much more than 32MB (and a lot of variables)? Maybe the memory freeing process could be in another thread and run without locking all other operations.

Thanks for the reply!
 [2008-08-12 10:49 UTC] gopalv82 at yahoo dot com
Can't run it another thread or without locks.

Last benchmark put a complete 32Mb cache flush in 800ms, which should be sane enough.

More improvements on cache flushes coming up, but it's reached sane enough levels to close thsi bug
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 00:01:35 2025 UTC