-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Batch Processing ,out of memory #6525
Comments
@imsheng this needs more details, such as:
|
in symfony console.
nothing else |
Run it with |
|
That still shows no trace, but the fact that it is crashing within the connection may indicate that the resultset is too big. |
what should I do? I need to deal with tens of millions of data |
Sadly, PDO does not have cursor-alike operations: mysqli does, for example. Just a hint though: if you are off doing million records operations, then the ORM is likely the wrong tool for the job... |
Ref: doctrine/dbal#2718 |
I tried this method, but still out of memory:
|
Are you clearing in between results? Also, that method is unsafe if data is
added or deleted during the batch operation
On 25 Jun 2017 12:55 PM, "imsheng" <[email protected]> wrote:
I tried this method, but still out of memory:
$count = $this->em->getRepository('AppBundle:xxxxxx')->createQueryBuilder('xxxxxxx')
->select('count(xxxxxxx) c')
->getQuery()
->getSingleScalarResult();
//count:4000,000
for ($i = 0; $i <= $count - 1; $i++) {
$xxx=
$this->em->getRepository('AppBundle:xxx')->createQueryBuilder('xx')
->setFirstResult($i)
->setMaxResults(1)
->getQuery()
->getSingleResult();
//nothing
}
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#6525 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAJakJzJ6PgYCote9yrQupLz2vOAdyrkks5sHjy6gaJpZM4OEjCI>
.
|
without update or insert.
what I do is a crawler |
Then there's a memleak somewhere else - this needs debugging either in your codebase, or be reproduced in an isolated test case within this library: I can't help further without any of those. |
Setting the variable to |
It doesn't: refcount works in the exact same way. If it doesn't, report a php-src bug. |
Running into this problem, too. I can't even get to iteration itself. It fails with OOM right here: $this->entityManager
->getRepository(UploadView::class)
->createQueryBuilder('v')
->orderBy('v.id', 'asc')
->getQuery()
->iterate(); Need to process 12M rows. I expected it to work the same way DBAL does because I don't have a problem iterating over a huge result set with DBAL. This time I need model objects tho. |
As a workaround, I ended up iterating over 10K rows at a time: $lastId = 0;
while (true) {
$iterable = $this->entityManager
->getRepository(UploadView::class)
->createQueryBuilder('v')
->where('v.id > :id')
->orderBy('v.id', 'asc')
->setMaxResults(10000)
->getQuery()
->iterate([
'id' => $lastId,
]);
$iterated = false;
foreach ($iterable as $row) {
$iterated = true;
/** @var UploadView $view */
$view = $row[0];
$lastId = $view->getId();
// do actual processing
$this->entityManager->detach($view);
}
$this->entityManager->clear();
if (!$iterated) {
break;
}
} |
Ah yes, fairly sure that the ORM doesn't lazily iterate over DBAL resultsets: that is a big issue that needs work. |
@Ocramius it would possibly be done for ORM v3.x, right? |
Yeah, not 2.x
…On 29 Oct 2017 19:44, "Luís Cobucci" ***@***.***> wrote:
Ah yes, fairly sure that the ORM doesn't lazily iterate over DBAL
resultsets: that is a big issue that needs work.
@Ocramius <https://github.com/ocramius> it would possibly be done for ORM
v3.x, right?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6525 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAJakADmwebqnVp7XH0c5w0C1JbRQiyQks5sxMd3gaJpZM4OEjCI>
.
|
worked for me |
Try this, works for me $conn = $emd->getConnection(); |
If you wish persist an entity, then you have this error To avoid this, create another Entity Manager with PDO::MYSQL_ATTR_USE_BUFFERED_QUERY to true (by default) and use merge. $emd2->merge($entity); |
It works perfectly |
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/batch-processing.html#iterating-large-results-for-data-processing
Total: 4000,000 rows
I tried the code and found that was out of memory
The text was updated successfully, but these errors were encountered: