Attempt to reduce max memory usage during actualize (#2955)

* Attempt to reduce max memory usage during actualize

#Fix https://github.com/FreshRSS/FreshRSS/issues/2952

* Use memory_get_peak_usage
pull/2963/head
Alexandre Alapetite 4 years ago committed by GitHub
parent be10486f5e
commit aea3806590
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      app/Controllers/feedController.php
  2. 9
      app/Models/Feed.php
  3. 2
      app/actualize_script.php

@ -333,9 +333,9 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$needFeedCacheRefresh = false;
// We want chronological order and SimplePie uses reverse order.
$entries = array_reverse($feed->entries());
if (count($entries) > 0) {
$entries = $feed->entries();
$nbEntries = count($entries);
if ($nbEntries > 0) {
$newGuids = array();
foreach ($entries as $entry) {
$newGuids[] = safe_ascii($entry->guid());
@ -346,7 +346,8 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$oldGuids = array();
// Add entries in database if possible.
foreach ($entries as $entry) {
for ($i = 0; $i < $nbEntries; $i++) {
$entry = $entries[$i];
if (isset($newGuids[$entry->guid()])) {
continue; //Skip subsequent articles with same GUID
}
@ -405,9 +406,12 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$entryDAO->addEntry($entry->toArray());
$nb_new_articles++;
}
unset($entry);
unset($entries[$i]);
}
$entryDAO->updateLastSeen($feed->id(), $oldGuids, $mtime);
}
unset($entries);
if (mt_rand(0, 30) === 1) { // Remove old entries once in 30.
if (!$entryDAO->inTransaction()) {
@ -455,6 +459,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$feed->unlock();
$updated_feeds++;
unset($feed);
gc_collect_cycles();
// No more than $maxFeeds feeds unless $force is true to avoid overloading
// the server.

@ -333,7 +333,12 @@ class FreshRSS_Feed extends Minz_Model {
$guids = array();
$hasUniqueGuids = true;
foreach ($feed->get_items() as $item) {
// We want chronological order and SimplePie uses reverse order.
for ($i = $feed->get_item_quantity() - 1; $i >= 0; $i--) {
$item = $feed->get_item($i);
if ($item == null) {
continue;
}
$title = html_only_entity_decode(strip_tags($item->get_title()));
$authors = $item->get_authors();
$link = $item->get_permalink();
@ -414,6 +419,7 @@ class FreshRSS_Feed extends Minz_Model {
}
$guid = $item->get_id(false, false);
unset($item);
$hasUniqueGuids &= empty($guids['_' . $guid]);
$guids['_' . $guid] = true;
$author_names = '';
@ -441,7 +447,6 @@ class FreshRSS_Feed extends Minz_Model {
}
$entries[] = $entry;
unset($item);
}
$hasBadGuids = $this->attributes('hasBadGuids');

@ -69,6 +69,7 @@ foreach ($users as $user) {
fwrite(STDERR, 'FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt') . "\n");
}
}
gc_collect_cycles();
}
Minz_Log::notice('FreshRSS actualize done.', ADMIN_LOG);
@ -78,6 +79,7 @@ if (defined('STDOUT')) {
$duration = date_diff($end_date, $begin_date);
fwrite(STDOUT, 'Ending feed actualization at ' . $end_date->format('c') . "\n"); //Unbuffered
fwrite(STDOUT, 'Feed actualizations took ' . $duration->format('%a day(s), %h hour(s), %i minute(s) and %s seconds') . ' for ' . count($users) . " users\n"); //Unbuffered
fwrite(STDOUT, 'Memory usage: ' . format_bytes(memory_get_peak_usage(true)) . "\n"); //Unbuffered
}
echo 'End.', "\n";
ob_end_flush();

Loading…
Cancel
Save