Schrift
[thread]870[/thread]

LWP für eine 400MB CSV-Datei.: kann das gehen...? (Seite 2)

Leser: 2


<< |< 1 2 >| >> 13 Einträge, 2 Seiten
GwenDragon
 2007-01-03 13:36
#9441 #9441
User since
2005-01-17
14837 Artikel
Admin1
[Homepage]
user image
[quote=olruebe01,03.01.2007, 03:50]Denn auch dann müsste die Datei ja in den Arbeitsspeicher eingelesen werden um diese dann in dei DB eintragen zu können.
Außerdem weiß ich inzwischen, dass einige csv's sogar 1,2 GB groß sind... Kann das klappen????[/quote]
Kommt darauf an, wieviel RAM und Swapspace dein Server für dich bereitstellt.
Kann aber eng werden, wenn es ein "normaler" Webserver für mehrere Leute oder ein Root-Srver mit wenig RAM ist.
esskar
 2007-01-03 13:41
#9442 #9442
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
jan hatte doch fast schon die lösung gegeben

Quote
ua->get( $url , $field_name => $value, ... )
This method will dispatch a GET request on the given $url. Further arguments can be given to initialize the headers of the request. These are given as separate name/value pairs. The return value is a response object. See the HTTP::Response manpage for a description of the interface it provides.

Fields names that start with ``:'' are special. These will not initialize headers of the request but will determine how the response content is treated. The following special field names are recognized:

:content_file => $filename
:content_cb => \&callback
:read_size_hint => $bytes
If a $filename is provided with the :content_file option, then the response content will be saved here instead of in the response object. If a callback is provided with the :content_cb option then this function will be called for each chunk of the response content as it is received from the server. If neither of these options are given, then the response content will accumulate in the response object itself. This might not be suitable for very large response bodies. Only one of :content_file or :content_cb can be specified. The content of unsuccessful responses will always accumulate in the response object itself, regardless of the :content_file or :content_cb options passed in.

The :read_size_hint option is passed to the protocol module which will try to read data from the server in chunks of this size. A smaller value for the :read_size_hint will result in a higher number of callback invocations.

The callback function is called with 3 arguments: a chunk of data, a reference to the response object, and a reference to the protocol object. The callback can abort the request by invoking die(). The exception message will show up as the ``X-Died'' header field in the response returned by the get() function.


diese callback-function kannst du dann nutzen, um die daten in die db zu schaufeln
olruebe01
 2007-01-13 02:59
#9443 #9443
User since
2006-01-19
192 Artikel
BenutzerIn
[default_avatar]
Hi,

sorry, dass ich mich erst jetzt melde, musste ein paar Tage weg.

Die Lösung habe ich gefunden und sie ist recht einfach (auch ohne SIMPLE):
Code: (dl )
1
2
3
4
 my $ua = LWP::UserAgent->new;
$ua->timeout(180);
$ua->env_proxy;
my $response = $ua->mirror("$URL", $file);


MIRROR sorgt dafür, dass die Datei direkt gespeichert wird und NICHT über den RAM läuft. Auf diese Weise schafft mein Server etwa 6-8 MB pro Sekunde und sowohl RAM, CPU und LoadAverage sind sehr entspannt...

Danke für Eure Hilfe.
<< |< 1 2 >| >> 13 Einträge, 2 Seiten



View all threads created 2006-12-31 20:45.