I’m using some python scripts to do statistics.
One sort content of logs are like this I call it A logs:
every A logs has the format of:
[2012-09-12 12:23:33] SOME_UNIQ_ID filesize
another logs I call it B logs has the format of:
[2012-09-12 12:24:00] SOME_UNIQ_ID
I need to count how many records in the A logs are also in the B logs, and get the time gap of the two records with the same record id.My implementation was load all time and ID of B logs into a map,then iterate the A logs to check if it’s ID was exist in the map.The problem is it casts too much memory cause I have almost 100 million records in B logs.Any suggestion to improve the performance and memory usage? Thanks.
You could try reversing the lookup depending if “A” fits into memory and sequentially scan “B”.
Otherwise, load the log files into a SQLite3 database with two tables (log_a, log_b) containing (timestamp, uniq_id, rest_of_line), then execute an SQL join on
uniq_id, and do any processing you require on the results from that. This will keep the memory overhead low, enables the SQL engine to do the join, but of course does require effectively duplicating the log files on-disk (but that’s generally not an issue on most systems)example
Note that:
.connecton sqlite3 should be a filenameaandbshould be your files