PHP UK Conference 2013

¡Socorro! Me estoy quedando sin memoria

Julien Pauli  · 

Transcripción

Extracto de la transcripción automática del vídeo realizada por YouTube.

so hello everybody i canna myself first so I'm Julian Pauline I've been programming HP for many years now i'm reviewing a PHP internals code so since about three four years I'm 55 Rudy's manager to get away with David perhaps you met him

maybe somewhere i'm working in Paris oh I'm French I apologize for my sometimes poor English I like writing technical articles about PHP about PHP internals and about open source software so i'm working at blah blah car in Paris it's mostly

website talking about car sharing you know through euros so we have many users we have iphone apps android application mobile etc and we run PHP PHP 5.3 actually okay so i'm trying through this talk to explain you how memory works in a unix system so i

expect from you then you have a little bit c programming experience and somehow sometimes a matching code hardware programming we won't see any line of code and I guess you are all PHP programmers all right and you have already experienced out of memory

on your PHP programs mainly in CLI scripts and we try to understand why and how memory works in an operating system and in PHP okay so what is memory we're going to talk about by stack heap in a process okay not too deep how to measure memory consumption

of any process then impeach what tools we get for that and we're going to try to understand how PHP manages memory in your script okay how it does to allocate and free memory and then how to measure PHP memory into a script so memory from a hardware point

of view you all know this i think and i think you know memory from a software point of view as well it's this ok so in linux it will be mainly in linux I don't really know windows internals and other UNIX it may be different in Linux every process

can can have can consume the same amount of memory were talking about virtual memory ok so I think you you help this this word before virtual memory is just an image of the physical memory that your process can allocate ok so when we talk about memory mainly

we talk about virtual memory we cannot allocate physical memory from user process ok we have to code into the kernel to allocate directory physical memory so in Linux every process has the illusion of being able to allocate the whole memory and Linux will

by default on the last version the colonel will always answer yes here is the memory ok so you can you can have two processes with a one-match in with say to jigga byte of memory those two processes can allocate both 2g bytes of memory at the same time but

the colonel won't give 2 gigawatts each because the machine and the physical hardware only guy on you get 1 times 2 gigawatts so it's going to swap and it's gonna play with internal tables ok so in a process like PHP you can allocate memory you

have to manners you can allocate memory on something called the stack and something called the heap I hope you you know you know those those terms so while running a process can allocate memory and then it can eat more and more memory talking about stuck in

heap I recall you that the starch it's just about a function argument pushing so when you call function that call function that call function etc you you gonna you're going to eat more and more memory from the stack ok so the starch can exhaust memory

as far as you call too many requisite functions in each other ok that's not a very common in inner process well it's easy to do just a function that calls itself and you're gonna exhaust the stack size but the most important is the heap memory

the heat memory its memory that the programmer can ask for at any time in the process slide ok and PHP is a process so PHP can ask for more memory from the heap ok using mainly dynamic allocation function like a malaka a map under linux and the programmer

the sea programmer has to free this memory by hand if it does not then you you have a memory leak so how can we monitor memory from the stock and from the heap from Linux point of view Linux is very very clever and give us tools for that perhaps you know the

prop file system under linux okay under the proc file system you have a v8 well it's a virtual file system and under and the proc you have any PID any process will create an entry in in this proc file system so if you have a process ID 2875 for you can

ask for is for its status ok just with gap and your have information and those informations if you look on the web you will have difficulties to know what it is about you have to mainly what i do is opening the kernel source and see what happens on that and

you have books that explain this so mainly you can see the virtual memory size this is the size the process actually asked for so this process is asking for a total of about twenty megabyte of virtual memory vitro not physical what is actually allocated in

physical memory is what is called resident set size so if you call top or tools like that under linux you will see mainly the virtual memory size so you will have the illusion that your process is actually eating 20 megabytes in your physical memory it's

not the case ok it is it can actually ask for 20 megabytes about ok but the colonel is actually allocating about three hundred kilobytes in physical memory and all these virtual memory size is divided with you know stack and heap and other segments I want

to talk about so you have the stuck here and you have mainly not really true but you can consider this is a heap memory ok so if you some both you should you should have the virtual memory size you have other segments I won't talk about because it's

a little bit complicated ok so that's the first the first way to monitor memory and linux you can use for example the watch command on this and then play with your process and you can see the memory which is moving so those numbers are real ok the colonel

gets you those numbers so you can trust them at least when you don't have Colonel bugs some some kernel have bugs and they don't really they display numbers that are not the real numbers but on the latest version it's ok in PHP so PHP is a process

like any other we just saw take care of functions like memory gates usage you should all know because memory gets usage will give you something you don't really know if its heat memories that memory if it's virtual memory of physical memory okay it's

not very very good to to trust the numbers at least when you don't know what they represent that's well what we were going to explain next ok so the memory is mainly divided in segments and you can ask for the memory map with the P map command and

under linux pass the X argument it's better because you don't you want sighs and on this process I don't know what it is so very small one because it's just found with c library this process you can see all the memory mappings okay and what

[ ... ]

Nota: se han omitido las otras 3.344 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.