Effective PyCharm Transcripts
Chapter: Performance and profiling
Lecture: Optimizing the database access
Login or
purchase this course
to watch this video and the rest of the course contents.
0:01
That's good, now let's focus on this get records thing. You'll see there's this read data, there's this read row and so on,
0:09
let's go down here to this run query, and it turns out read row is slow to create connection maybe, we could use connection pooling
0:16
that's a possibility, we could think about how that might work, but let's go over here, we'd have to simulate this
0:24
in a real database app it would actually automatically do that so let's go check this one out.
0:29
Now, let's suppose we've looked at this read row business and you can see I'm just faking this for our little demo
0:35
we learned that there was actually no index on this database on this particular query that we're running and there's a lot of data,
0:45
so the difference between having a large amount of data within index and not can easily be a thousand times faster,
0:53
so let's suppose we go over to the database and we're like, we're going to put an index and make it a hundred times faster,
0:59
so we improved it by adding an index, so we're going to go run this again and see how we're doing, I don't want regular to run, I want profile to run
1:16
I got our answers, let's zoom in again and see what we got going on so now we look get records is actually still slow
1:24
but it's really about creating this connection and this whole part about reading the rows, like literally fell off the map
1:34
because it was under some sort of threshold, let's go back and actually imagine we could do some sort of connection pooling
1:42
again this is just fake, like I said, real database connections, systems like SQLAlchemy would take care of this
1:47
but let's just go say this and let's imagine that we could say if we have it, we're just going to return the connection
2:02
otherwise we have to create it, and we'll set the connection to that and then we'll return the connection. This is what connection,
2:12
at least some sort of shared connection would look like, connection pooling will have a set we could get from
2:18
but let's see how this works, I think we probably got our get records just completely flying now,
2:24
all right put that over here, have a look at the call graph so down here we call get records nine times
2:30
we call get connection and it only takes that time that it took for one of them and then that was it, it took a while to create the first connection
2:38
but no matter how many times we call it now it's going to be open and it's going to be flying so these things are really going pretty well
2:45
and this one is looking worse and worse compared to its friends, it's red right, so let's go and work on this one
2:51
and then we'll see what else we can do.