Re: [Python] RAM e dimensioni file
Marco Mariani ha scritto: > Roberto Bettazzoni wrote: > >> In allegato trovi una prova che ho fatto al volo, >> sul mio windows XP con 2 Gb RAM liberi si blocca verso i 430 Mb >> >> Ci sara' un perche', ma lo ignoro. > > Perche' hai 430 milioni di elementi (non byte, ottetti o caratteri), in > una lista che occupa 2GB. > Hai ragione ... ma non torna :-) Giusto, sono elementi non byte. > Conosco un posto dove ti danno una botta in testa nel punto giusto, e > dimentichi il C, se interessa ;) Si, passami l'indirizzo, mi sa che ne ho bisogno. ;-) Pero' ancora non torna: ho rifatto la prova su una macchina con 4 Gb RAM (Win ne vede 3) e monitorando l'occupazione delle memoria del processo "python". Il processo occupa al massimo circa 1.5 Gb, il resto e' libero. Risultato simile a quello ottenuto su un PC con 2 Gb RAM Idee? Roberto ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] RAM e dimensioni file
Ernesto wrote: > Le info, inoltre, non sono organizzate in modo tale da poter leggere il file > un > po' per volta. > Neanche XML, se ti puo' consolare :) ma ci sono dei parser come pulldom, che sono fatti apposta per gestire grosse quantita' di dati senza tenerli in memoria. >> E' raro che non esistano alternative. >> > > Forse l'alternativa c'è ma sono ancora riuscito a trovarla. > Guardaci meglio... Non conosco l'origine dei dati, eppure sono sicuro che il mese prossimo saranno gia' raddoppiati, in media. -- This e-mail (and any attachment(s)) is strictly confidential and for use only by intended recipient(s). Any use, distribution, reproduction or disclosure by any other person is strictly prohibited. The content of this e-mail does not constitute a commitment by the Company except where provided for in a written agreement between this e-mail addressee and the Company. If you are not an intended recipient(s), please notify the sender promptly and destroy this message and its attachments without reading or saving it in any manner. Any non authorized use of the content of this message constitutes a violation of the obligation to abstain from learning of the correspondence among other subjects, except for more serious offence, and exposes the person responsible to the relevant consequences. ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] RAM e dimensioni file
> Come elabori il file? > Perche' vuoi caricare tutto in memoria? Il file contiene tutta una serie di info che devono essere organizzate in dizionari per un rapido accesso nel corso dello script. Le info, inoltre, non sono organizzate in modo tale da poter leggere il file un po' per volta. > E' raro che non esistano alternative. Forse l'alternativa c'è ma sono ancora riuscito a trovarla. Ernesto ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] RAM e dimensioni file
simozack wrote: > Conosco anche un posto dove questi messaggi sono inutili, come ad > esempio le ML pubbliche. > Ringrazia che non ho messo la versione completa in italiano e inglese, come prevede la policy aziendale. -- This e-mail (and any attachment(s)) is strictly confidential and for use only by intended recipient(s). Any use, distribution, reproduction or disclosure by any other person is strictly prohibited. The content of this e-mail does not constitute a commitment by the Company except where provided for in a written agreement between this e-mail addressee and the Company. If you are not an intended recipient(s), please notify the sender promptly and destroy this message and its attachments without reading or saving it in any manner. Any non authorized use of the content of this message constitutes a violation of the obligation to abstain from learning of the correspondence among other subjects, except for more serious offence, and exposes the person responsible to the relevant consequences. ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] RAM e dimensioni file
2009/9/24 Marco Mariani : > This e-mail (and any attachment(s)) is strictly confidential and for use only > by intended recipient(s). Any use, distribution, reproduction or disclosure > by any other person is strictly prohibited. The content of this e-mail does > not constitute a commitment by the Company except where provided for in a > written agreement between this e-mail addressee and the Company. If you are > not an intended recipient(s), please notify the sender promptly and destroy > this message and its attachments without reading or saving it in any manner. > Any non authorized use of the content of this message constitutes a violation > of the obligation to abstain from learning of the correspondence among other > subjects, except for more serious offence, and exposes the person responsible > to the relevant consequences. Conosco anche un posto dove questi messaggi sono inutili, come ad esempio le ML pubbliche. Ma vabbè, oggi sono acido io... :) Ciao, Simone ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] RAM e dimensioni file
Ernesto wrote: > 1. stimando la quantità di memoria necessaria per allocare un intero > file, per cui l'utente potrà decidere se andare avanti o meno Come elabori il file? Perche' vuoi caricare tutto in memoria? E' raro che non esistano alternative. -- This e-mail (and any attachment(s)) is strictly confidential and for use only by intended recipient(s). Any use, distribution, reproduction or disclosure by any other person is strictly prohibited. The content of this e-mail does not constitute a commitment by the Company except where provided for in a written agreement between this e-mail addressee and the Company. If you are not an intended recipient(s), please notify the sender promptly and destroy this message and its attachments without reading or saving it in any manner. Any non authorized use of the content of this message constitutes a violation of the obligation to abstain from learning of the correspondence among other subjects, except for more serious offence, and exposes the person responsible to the relevant consequences. ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] RAM e dimensioni file
Roberto Bettazzoni wrote: > In allegato trovi una prova che ho fatto al volo, > sul mio windows XP con 2 Gb RAM liberi si blocca verso i 430 Mb > > Ci sara' un perche', ma lo ignoro. Perche' hai 430 milioni di elementi (non byte, ottetti o caratteri), in una lista che occupa 2GB. Conosco un posto dove ti danno una botta in testa nel punto giusto, e dimentichi il C, se interessa ;) -- This e-mail (and any attachment(s)) is strictly confidential and for use only by intended recipient(s). Any use, distribution, reproduction or disclosure by any other person is strictly prohibited. The content of this e-mail does not constitute a commitment by the Company except where provided for in a written agreement between this e-mail addressee and the Company. If you are not an intended recipient(s), please notify the sender promptly and destroy this message and its attachments without reading or saving it in any manner. Any non authorized use of the content of this message constitutes a violation of the obligation to abstain from learning of the correspondence among other subjects, except for more serious offence, and exposes the person responsible to the relevant consequences. ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] RAM e dimensioni file
IMHO, ti stai complicando inutilmente la vita. Proprio per farla semplice, non esiste piu' il concetto di "memoria libera" ma si usa quello di "memoria ancora non utilizzata". Questo perche' e' oramai un assioma che memoria non utilizzata e' uguale a memoria sprecata. Per questo motivo, su qualsiasi sistema operativo moderno dopo poco tempo troverai tutta (o buona parte) della memoria occupata anche se apparentemente non la sta usando nessuno. Buona parte su Linux viene utilizzata per la page cache e all'occorrenza viene ridata ai processi che ne abbiano bisogno. Poi hai la swap, che per il tuo processo e' memoria utilizzabile. Ci sono poi i limiti che ogni bravo sysadmin dovrebbe imporre ai processi non privilegiati, tra cui c'e' anche quello della memoria virtuale (l'address space). Sono gia' tre cose che devi tenere in considerazione. Non vuoi che il tuo file finisca in swap ? allora dovrai allocare la memoria e poi lockarla oppure usare la funzione (in C) mlockall(MCL_FUTURE) che locka tutto il cucuzzaro. Questo introduce un'altra porzione al tuo codice (tra l'altro non so neanche se mlockall sia esportata in python o se dovrai implementarla a manina). Una prima formula per ricavare quanta memoria ha a disposizione il tuo processo potrebbe essere: Memoria_fisica_libera + Page_Cache (li ricavi sempre leggendo /proc/meminfo) Poi devi usare getrlimit() per sapere se la memoria che puo' mappare il tuo processo rientra nei limiti. Per sapere quanta memoria ha mappato gia' il tuo processo devi leggere il file /proc/self/stat ("man proc" ti aiutera' a farne il parsing) Tieni sempre a mente che si sta parlando di memoria virtuale, sapere quanta memoria fisica occupa un processo e' materia oscura, e Linux stesso si basa su un compromesso che spesso e volentieri non corrisponde a realta'. Per questo motivo non puoi neanche limitare la quantita' di memoria fisica che un singolo processo (sebbene setrlimit lo preveda) puo' allocare. Se dopo tutto questo pippone sei ancora convinto che sia l'approccio giusto, direi che hai tutto cio' che ti serve :) Grazie mille per tutte le precisazioni. In teoria credo che l'approccio sia corretto o almeno lecito. In pratica le cose cambiano poiché per quello che ho inteso non è semplice tradurre il tutto in codice platform independent. Probabilmente posso aggirare l'ostacolo in due modi diversi: 1. stimando la quantità di memoria necessaria per allocare un intero file, per cui l'utente potrà decidere se andare avanti o meno 2. caricare il file in memoria fin quando sarà sollevata un'eccezione. Se questa eventualità si dovesse verificare, le info necessarie del file saranno indicizzate su disco. Questo rallenterà un po' lo script ma va bene così... Ernesto___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python