Skip to content
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

Something is wrong with the performance on big data #543

Closed
RezaT1994 opened this issue Dec 15, 2021 · 3 comments
Closed

Something is wrong with the performance on big data #543

RezaT1994 opened this issue Dec 15, 2021 · 3 comments
Labels
bug An existing feature is not working as intended

Comments

@RezaT1994
Copy link

RezaT1994 commented Dec 15, 2021

Describe the bug
When I query the first 5000 rows of a table, it takes about 10 seconds to respond

Expected behavior
It should be a lot faster. as it was in orator

Screenshots or code snippets

class Product(SoftDeletesMixin, Model):
	pass

products = Product.where('is_active', '1').limit(5000).get()
print(products[0].id) # 1

here is the query log:

Running query SELECT * FROM `products` WHERE `products`.`is_active` = %s AND `products`.`deleted_at` IS NULL LIMIT 5000, ['1']. Executed in 0.20ms

Desktop:

  • OS: [Windows]
  • Version [11]

What database are you using?

  • Type: [MySQ]
  • Version [8.0.26]
  • Masonite ORM [v1.0.65]
@RezaT1994 RezaT1994 added the bug An existing feature is not working as intended label Dec 15, 2021
@RezaT1994 RezaT1994 changed the title Something wrong with the performance on big data Something is wrong with the performance on big data Dec 15, 2021
@josephmancuso
Copy link
Member

josephmancuso commented Dec 15, 2021

You really should not be loading 5000 rows into memory like that. It is much better to use chunking. I'm not sure how much faster Orator was from Masonite ORM but the slowness comes from hydrating 5000 models in memory and not the query. Not really anything we can do unless you improve your query.

Here is an example on the same query above but chunking through the results:

products_chunk = Product.where('is_active', '1').limit(5000).chunk(200)
for product in products_chunk:
    print(product.id)

Chunking uses a generator which is much faster and uses much less memory.

@RezaT1994
Copy link
Author

Now when I use eager loading, It's like not working with chunk. It's working when using get

Product.with_trashed().with_('brand').limit(5000).chunk(200)

@josephmancuso
Copy link
Member

Fixed in #553

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing feature is not working as intended
Projects
None yet
Development

No branches or pull requests

2 participants