This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from celery import Celery | |
from datetime import datetime | |
app = Celery('tasks') | |
# Setting the task_always_eager to to true for demonstrating the issue | |
# You don't want to set it to true in production environments | |
app.conf.task_always_eager = True | |
def convert_to_iso(timestamp): | |
''' Convert Unix timestamp to an ISO string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE author ( | |
id bigserial primary key, | |
name varchar(64) not null, country varchar(64) | |
); | |
CREATE TABLE book ( | |
id bigserial primary key, | |
title varchar(128) not null, | |
author_id bigint NOT NULL, | |
CONSTRAINT fk_books_author_id FOREIGN KEY (author_id) REFERENCES author(id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
NUM_AUTHORS = 10000000 | |
NUM_BOOKS = 20000000 | |
# Any author can wite any book | |
author_sql = """INSERT INTO author (id, name) values ({i}, 'author_{i}');\n""" | |
book_sql = """INSERT INTO book (title, author_id) values ('title_{i}', {author_id});\n""" | |
data_file = open('data.sql', 'w') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QUERY PLAN | |
------------------------------------------------------------------------------------------------------------------------------------------- | |
Limit (cost=0.87..51.28 rows=100 width=206) (actual time=0.023..24.739 rows=100 loops=1) | |
Buffers: shared hit=255 read=149 | |
-> Nested Loop (cost=0.87..10080882.37 rows=20000000 width=206) (actual time=0.023..24.714 rows=100 loops=1) | |
Buffers: shared hit=255 read=149 | |
-> Index Scan using book_pkey on book (cost=0.44..666418.44 rows=20000000 width=30) (actual time=0.012..0.069 rows=100 loops=1) | |
Buffers: shared hit=4 | |
-> Index Scan using author_pkey on author (cost=0.43..0.47 rows=1 width=168) (actual time=0.245..0.245 rows=1 loops=100) | |
Index Cond: (id = book.author_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QUERY PLAN | |
------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
Limit (cost=1038449.15..1038460.82 rows=100 width=206) (actual time=23225.822..26199.674 rows=100 loops=1) | |
Buffers: shared hit=9749 read=201159, temp read=182633 written=195896 | |
-> Gather Merge (cost=1038449.15..2983029.28 rows=16666666 width=206) (actual time=23225.820..26199.659 rows=100 loops=1) | |
Workers Planned: 2 | |
Workers Launched: 2 | |
Buffers: shared hit=9749 read=201159, temp read=182633 written=195896 | |
-> Sort (cost=1037449.13..1058282.46 rows=8333333 width=206) (actual time=23219.185..23219.219 rows=75 loops=3) | |
Sort Key: book.title, book.id |