This is an automated email from the ASF dual-hosted git repository.

bchapuis pushed a commit to branch mbtiles-perf
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git


The following commit(s) were added to refs/heads/mbtiles-perf by this push:
     new dcfb503c Log long queries
dcfb503c is described below

commit dcfb503ca8082845cb526a2b669142439ccfecf4
Author: Bertil Chapuis <[email protected]>
AuthorDate: Tue Aug 22 17:38:11 2023 +0200

    Log long queries
---
 .../apache/baremaps/tilestore/postgres/PostgresTileStore.java  | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/postgres/PostgresTileStore.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/postgres/PostgresTileStore.java
index 8f531921..25f862d2 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/postgres/PostgresTileStore.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/postgres/PostgresTileStore.java
@@ -100,14 +100,15 @@ public class PostgresTileStore implements TileStore {
   /** {@inheritDoc} */
   @Override
   public ByteBuffer read(TileCoord tileCoord) throws TileStoreException {
+    String sql = withQuery(tileCoord);
     try (Connection connection = datasource.getConnection();
         Statement statement = connection.createStatement();
         ByteArrayOutputStream data = new ByteArrayOutputStream()) {
 
       int length = 0;
       if (queries.stream().anyMatch(query -> zoomPredicate(query, 
tileCoord.z()))) {
-        String sql = withQuery(tileCoord);
         logger.debug("Executing query: {}", sql);
+        long start = System.currentTimeMillis();
         try (GZIPOutputStream gzip = new GZIPOutputStream(data);
             ResultSet resultSet = statement.executeQuery(sql)) {
           while (resultSet.next()) {
@@ -116,6 +117,13 @@ public class PostgresTileStore implements TileStore {
             gzip.write(bytes);
           }
         }
+        long stop = System.currentTimeMillis();
+        long duration = stop - start;
+        if (duration > 1000) {
+          logger.warn("Executed query for tile {} in {} ms: {}", tileCoord, 
duration, sql);
+        } else {
+          logger.debug("Executed query for tile {} in {} ms: {}", tileCoord, 
duration, sql);
+        }
       }
 
       if (length > 0) {

Reply via email to