FlaskSQLAlchemy query very slow












0















I'm facing a problem concerning performance when using the FlaskSQLAlchemy query function. With a database size of ca. 400 MB, a query containing all elements takes nearly 100 seconds.



Here is the query:



start_time = time.time()
results = DataPoint.query.all()
end_time = time.time()
print("All Datapoints: ", results)
print("Number of elements:", len(results))
print("Time elapsed: ", end_time-start_time)


Output: Number of elements: 5871988
Time elapsed: 96.98983788490295



with DataPoint being:



class DataPoint(db.Model):
id = db.Column(db.Integer, primary_key=True)
sensor_type = db.Column(db.String(75), nullable=False)
sensor_number = db.Column(db.Integer)
serial_number = db.Column(db.Float, db.ForeignKey('sensor_box.serial_number'), nullable=False)
sensor_value = db.Column(db.Float, nullable=False)
date_time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)


is this long duration normal, or am I doing something wrong?



Thanks in advance










share|improve this question




















  • 2





    ORMs do sacrifice performance for convenience. There are a lot of variables that can play into this, size of the result set, available memory, is the database remote or local etc.. There is a whole page in the docs about ORM query performance, with a particular section about ORM Selects.

    – SuperShoot
    Nov 25 '18 at 12:38








  • 1





    Did you try this: stackoverflow.com/questions/33738467/…

    – Ganesh K
    Nov 25 '18 at 12:45











  • yes I set it to False, thx

    – zerocool
    Nov 25 '18 at 12:45


















0















I'm facing a problem concerning performance when using the FlaskSQLAlchemy query function. With a database size of ca. 400 MB, a query containing all elements takes nearly 100 seconds.



Here is the query:



start_time = time.time()
results = DataPoint.query.all()
end_time = time.time()
print("All Datapoints: ", results)
print("Number of elements:", len(results))
print("Time elapsed: ", end_time-start_time)


Output: Number of elements: 5871988
Time elapsed: 96.98983788490295



with DataPoint being:



class DataPoint(db.Model):
id = db.Column(db.Integer, primary_key=True)
sensor_type = db.Column(db.String(75), nullable=False)
sensor_number = db.Column(db.Integer)
serial_number = db.Column(db.Float, db.ForeignKey('sensor_box.serial_number'), nullable=False)
sensor_value = db.Column(db.Float, nullable=False)
date_time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)


is this long duration normal, or am I doing something wrong?



Thanks in advance










share|improve this question




















  • 2





    ORMs do sacrifice performance for convenience. There are a lot of variables that can play into this, size of the result set, available memory, is the database remote or local etc.. There is a whole page in the docs about ORM query performance, with a particular section about ORM Selects.

    – SuperShoot
    Nov 25 '18 at 12:38








  • 1





    Did you try this: stackoverflow.com/questions/33738467/…

    – Ganesh K
    Nov 25 '18 at 12:45











  • yes I set it to False, thx

    – zerocool
    Nov 25 '18 at 12:45
















0












0








0








I'm facing a problem concerning performance when using the FlaskSQLAlchemy query function. With a database size of ca. 400 MB, a query containing all elements takes nearly 100 seconds.



Here is the query:



start_time = time.time()
results = DataPoint.query.all()
end_time = time.time()
print("All Datapoints: ", results)
print("Number of elements:", len(results))
print("Time elapsed: ", end_time-start_time)


Output: Number of elements: 5871988
Time elapsed: 96.98983788490295



with DataPoint being:



class DataPoint(db.Model):
id = db.Column(db.Integer, primary_key=True)
sensor_type = db.Column(db.String(75), nullable=False)
sensor_number = db.Column(db.Integer)
serial_number = db.Column(db.Float, db.ForeignKey('sensor_box.serial_number'), nullable=False)
sensor_value = db.Column(db.Float, nullable=False)
date_time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)


is this long duration normal, or am I doing something wrong?



Thanks in advance










share|improve this question
















I'm facing a problem concerning performance when using the FlaskSQLAlchemy query function. With a database size of ca. 400 MB, a query containing all elements takes nearly 100 seconds.



Here is the query:



start_time = time.time()
results = DataPoint.query.all()
end_time = time.time()
print("All Datapoints: ", results)
print("Number of elements:", len(results))
print("Time elapsed: ", end_time-start_time)


Output: Number of elements: 5871988
Time elapsed: 96.98983788490295



with DataPoint being:



class DataPoint(db.Model):
id = db.Column(db.Integer, primary_key=True)
sensor_type = db.Column(db.String(75), nullable=False)
sensor_number = db.Column(db.Integer)
serial_number = db.Column(db.Float, db.ForeignKey('sensor_box.serial_number'), nullable=False)
sensor_value = db.Column(db.Float, nullable=False)
date_time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)


is this long duration normal, or am I doing something wrong?



Thanks in advance







python sqlalchemy flask-sqlalchemy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 13:04









davidism

65.1k12172188




65.1k12172188










asked Nov 25 '18 at 12:32









zerocoolzerocool

204




204








  • 2





    ORMs do sacrifice performance for convenience. There are a lot of variables that can play into this, size of the result set, available memory, is the database remote or local etc.. There is a whole page in the docs about ORM query performance, with a particular section about ORM Selects.

    – SuperShoot
    Nov 25 '18 at 12:38








  • 1





    Did you try this: stackoverflow.com/questions/33738467/…

    – Ganesh K
    Nov 25 '18 at 12:45











  • yes I set it to False, thx

    – zerocool
    Nov 25 '18 at 12:45
















  • 2





    ORMs do sacrifice performance for convenience. There are a lot of variables that can play into this, size of the result set, available memory, is the database remote or local etc.. There is a whole page in the docs about ORM query performance, with a particular section about ORM Selects.

    – SuperShoot
    Nov 25 '18 at 12:38








  • 1





    Did you try this: stackoverflow.com/questions/33738467/…

    – Ganesh K
    Nov 25 '18 at 12:45











  • yes I set it to False, thx

    – zerocool
    Nov 25 '18 at 12:45










2




2





ORMs do sacrifice performance for convenience. There are a lot of variables that can play into this, size of the result set, available memory, is the database remote or local etc.. There is a whole page in the docs about ORM query performance, with a particular section about ORM Selects.

– SuperShoot
Nov 25 '18 at 12:38







ORMs do sacrifice performance for convenience. There are a lot of variables that can play into this, size of the result set, available memory, is the database remote or local etc.. There is a whole page in the docs about ORM query performance, with a particular section about ORM Selects.

– SuperShoot
Nov 25 '18 at 12:38






1




1





Did you try this: stackoverflow.com/questions/33738467/…

– Ganesh K
Nov 25 '18 at 12:45





Did you try this: stackoverflow.com/questions/33738467/…

– Ganesh K
Nov 25 '18 at 12:45













yes I set it to False, thx

– zerocool
Nov 25 '18 at 12:45







yes I set it to False, thx

– zerocool
Nov 25 '18 at 12:45














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467471%2fflasksqlalchemy-query-very-slow%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467471%2fflasksqlalchemy-query-very-slow%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin