1 of 15

APC

Some useful tuning

2 of 15

2 caching mechanism

Memory cache

for long operations and calculations

Opcode cache

for skipping code interpretation

3 of 15

Opcode

The Vulcan Logic Disassembler

4 of 15

Tuning opcode cache

apc.max_file_size (1M)

Files bigger then that wouldn't be cached.

apc.num_files_hint (1000)

Number of files that will be cached. Increase it.

apc.file_md5 (0)

Keep it 0, it's a lie

apc.ttl (0)

How long the file will stay cached

5 of 15

Tuning opcode cache

apc.stat (1)

Rechecking if file was updated. Set it to 0.

6 of 15

Tuning opcode cache

strace -e trace=file httpd -X

7 of 15

Tuning opcode cache

apc.stat (1)

Rechecking if file was updated. Set it to 0.

apc.slam_defense (1)

Prevents mass caching on startup. Set to 0

apc.write_lock (1)

Prevents locking of parallel requests

apc.file_update_protection (2)

Seconds to wait before new file gets cached

8 of 15

Extra control on opcode caching

apc.filter (null)

Regexp: cache only matching it files.

apc.cache_by_default (1)

Caches all php files. If set to 0 - it would use the filter

apc.canonicalize (1)

Convert relative path's into canonical.

Set to 0 and always use absolute path's.

9 of 15

Now User Cache

10 of 15

Concurrent locking

File locks

Basic locking mechanism. Very slow.

IPC Semaphore locks

Semaphores (provided by the OS). Better then file locks

Linux Futex locks

Linux specific mechanism. Significant gain. ( user space )

Pthread mutexes

Almost same as futex ( kernel space)

Spin locks

Extremely fast. Ported from Postgres. Eats your cpu

11 of 15

12 of 15

Use igbinary

Serialization sucks

Example array: [1,2,'hi']

13 of 15

Use igbinary

14 of 15

Apc constants

Regular defines are uber slow

15 of 15

Prime cache before start

Preload cache with data before going public

apc_store()

apc_compile_file()