[pyar] Cargar librería una única vez corriendo muchos procesos

Matías Lang shareman1204 en gmail.com
Jue Ago 6 17:32:21 ART 2015


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256



On 06/08/15 09:44, Daniel wrote:>
> 
> Me supera por mucho el tema del hilo pero... Hablando de video,
> 45Mb no es una exorbitancia, ¿estas seguro que es la librería que
> ocupa la memoria o será un buffer o algo así?
> 
> 
Con hacer un "import cv2" o "from cv2 import X" ya usa esos 45MB.
Después correr mi código usa unos 80MB más.

On 06/08/15 09:15, Andres Riancho wrote:
> Medir uso de memoria es algo difícil cuando usas multiprocessing,
> no todas las tools muestran la data de la misma manera y hay veces
> que suman variables que no tienen tanto sentido que esten juntas.
> 
> Ojo con una cosa... multiprocessing (al menos en python2) usa
> os.fork, por lo que te vas a encontrar en esta situacion:
> 
> """ In Unix systems equipped with virtual memory support
> (practically all modern variants), the fork operation creates a
> separate address space for the child. The child process has an
> exact copy of all the memory segments of the parent process, though
> if copy-on-write semantics are implemented, the physical memory
> need not be actually copied. Instead, virtual memory pages in both
> processes may refer to the same pages of physical memory until one
> of them writes to such a page: then it is copied. This optimization
> is important in the common case where fork is used in conjunction
> with exec to execute a new program: typically, the child process
> performs only a small set of actions before it ceases execution of
> its program in favour of the program to be started, and it requires
> very few, if any, of its parent's data structures. """
> 
> Es decir, el proceso hijo esta utilizando X memoria virtual, que
> en realidad no termina siendo memoria física porque no escribe 
> (idealmente) nunca a esas páginas de memoria (porque es la memoria 
> utilizada por una librería).
> 
> Volviendo a mi primer oración, lo que puede llegar a pasar es que 
> cuando mediste memoria (con alguna tool?) no se hizo una
> diferencia entre memoria virtual y física utilizada por el hijo,
> llevandote a creer una cosa que no era.
> 
> Todo esto es solo una teoria pero espero te sirva para llegar a la
> verdad :)
Corrí ps auxf que al parecer mide memoria física y todos los
subprocesos consumen los 45MB de opencv. También estoy usando la
herramienta mprof del paquete memory_profiler para graficar el consumo
y mide parecido.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCAAGBQJVw8RJAAoJEOYNHtvg7gKbktIP/RMeP7HUlA/qe+UqoG4SoYwD
1C6RESKW7NvdUE1XaRz10juQWSZcM9xHGpyaIgel0NBJUheZsv74iUNqduZkUhlz
DyO30gEJA3MfoLddWUgkLMdZWThGW6kmLK7bxQyUyy4pD5knopYcUUrfDFSl67i5
4dqZfG4fdFPTX0MxzWPKsSVRJrES9eKvdbQji5ZTqq+dkNGPmmPsA2sSq61sbxRA
S1BGLEfPTRnFGElQah50sOiyrETP3V1VIZ2byFD3fbofafc4Ls1vsFdFapRIm7C4
WZ/VEj8+D3l07wb+jAvrNWnErxdCMoTgmLibtAwqnSPW6q3pU4M3sgz5TLEYETq0
khFFpnl4/j3iSixF5yO/dvBhNUwETijpQyd7vA1naI6YrsFUAGYiMDNlJVEJRTS8
K8wLtdHRaA3ANocY9AB6e61tYSoU031LuZJs60Zhn60Cfml2l69kL+y5v7abQ58U
XdQSTQ3Kj5bHIm5oYwcBg4bbwBeVIriKXre1JYplJ4zVIQGy+rsJTGmmJm76DAIG
ld+rdlyi4o48sEynEhcfl09tr1w9j5Z4HkU7/b9I1yG1+6lDi6E4KgpDrzbww4vo
/jl9TjoB5APYuSzMnfe/mKyJssoAWK0CqCizgK8daUHsrV2dqL/JPDlNHkiBK848
+nawjR0cvRyPct5cMAuM
=M0Q1
-----END PGP SIGNATURE-----


More information about the pyar mailing list