cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sn...@apache.org
Subject [1/3] cassandra git commit: UDF / UDA execution time in trace
Date Sat, 18 Jul 2015 16:06:45 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.2 506068b18 -> e651fdd5f
  refs/heads/trunk 2eda224d2 -> 030762aa2


UDF / UDA execution time in trace

patch by Christopher Batey; reviewed by Robert Stupp for CASSANDRA-9723


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/e651fdd5
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/e651fdd5
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/e651fdd5

Branch: refs/heads/cassandra-2.2
Commit: e651fdd5f6bb5fee89dbfcb203a47c6a6dc79872
Parents: 506068b
Author: Christopher Batey <christopher.batey@gmail.com>
Authored: Sat Jul 18 17:51:00 2015 +0200
Committer: Robert Stupp <snazy@snazy.de>
Committed: Sat Jul 18 17:51:00 2015 +0200

----------------------------------------------------------------------
 CHANGES.txt                                          |  3 +++
 doc/cql3/CQL.textile                                 |  6 +++---
 .../apache/cassandra/cql3/functions/UDAggregate.java | 15 ++++++++++++++-
 .../apache/cassandra/cql3/functions/UDFunction.java  |  7 ++++++-
 4 files changed, 26 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/e651fdd5/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 35801bb..bd70d19 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,6 @@
+2.2.1
+ * UDF / UDA execution time in trace (CASSANDRA-9723)
+
 2.2.0
  * Fix cqlsh copy methods and other windows specific issues (CASSANDRA-9795) 
  * Don't wrap byte arrays in SequentialWriter (CASSANDRA-9797)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e651fdd5/doc/cql3/CQL.textile
----------------------------------------------------------------------
diff --git a/doc/cql3/CQL.textile b/doc/cql3/CQL.textile
index 2749d35..47a836b 100644
--- a/doc/cql3/CQL.textile
+++ b/doc/cql3/CQL.textile
@@ -1938,7 +1938,7 @@ User-defined aggregates can be used in "@SELECT@":#selectStmt statement.
 A complete working example for user-defined aggregates (assuming that a keyspace has been
selected using the "@USE@":#useStmt statement):
 
 bc(sample).. 
-CREATE FUNCTION averageState ( state tuple<int,bigint>, val int )
+CREATE OR REPLACE FUNCTION averageState ( state tuple<int,bigint>, val int )
   CALLED ON NULL INPUT
   RETURNS tuple<int,bigint>
   LANGUAGE java
@@ -1950,7 +1950,7 @@ CREATE FUNCTION averageState ( state tuple<int,bigint>, val int
)
     return state;
   ';
 
-CREATE FUNCTION averageFinal ( state tuple<int,bigint> )
+CREATE OR REPLACE FUNCTION averageFinal ( state tuple<int,bigint> )
   CALLED ON NULL INPUT
   RETURNS double
   LANGUAGE java
@@ -1962,7 +1962,7 @@ CREATE FUNCTION averageFinal ( state tuple<int,bigint> )
     return Double.valueOf(r);
   ';
 
-CREATE AGGREGATE average ( int )
+CREATE OR REPLACE AGGREGATE average ( int )
   SFUNC averageState
   STYPE tuple<int,bigint>
   FINALFUNC averageFinal

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e651fdd5/src/java/org/apache/cassandra/cql3/functions/UDAggregate.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/functions/UDAggregate.java b/src/java/org/apache/cassandra/cql3/functions/UDAggregate.java
index c9fbbaa..5f4d107 100644
--- a/src/java/org/apache/cassandra/cql3/functions/UDAggregate.java
+++ b/src/java/org/apache/cassandra/cql3/functions/UDAggregate.java
@@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory;
 
 import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.exceptions.InvalidRequestException;
+import org.apache.cassandra.tracing.Tracing;
 
 /**
  * Base class for user-defined-aggregates.
@@ -142,6 +143,9 @@ public class UDAggregate extends AbstractFunction implements AggregateFunction
     {
         return new Aggregate()
         {
+            private long stateFunctionCount;
+            private long stateFunctionDuration;
+
             private ByteBuffer state;
             {
                 reset();
@@ -149,6 +153,8 @@ public class UDAggregate extends AbstractFunction implements AggregateFunction
 
             public void addInput(int protocolVersion, List<ByteBuffer> values) throws
InvalidRequestException
             {
+                long startTime = System.nanoTime();
+                stateFunctionCount++;
                 List<ByteBuffer> fArgs = new ArrayList<>(values.size() + 1);
                 fArgs.add(state);
                 fArgs.addAll(values);
@@ -162,19 +168,26 @@ public class UDAggregate extends AbstractFunction implements AggregateFunction
                 {
                     state = stateFunction.execute(protocolVersion, fArgs);
                 }
+                stateFunctionDuration += (System.nanoTime() - startTime) / 1000;
             }
 
             public ByteBuffer compute(int protocolVersion) throws InvalidRequestException
             {
+                // final function is traced in UDFunction
+                Tracing.trace("Executed UDA {}: {} call(s) to state function {} in {}\u03bcs",
name(), stateFunctionCount, stateFunction.name(), stateFunctionDuration);
                 if (finalFunction == null)
                     return state;
+
                 List<ByteBuffer> fArgs = Collections.singletonList(state);
-                return finalFunction.execute(protocolVersion, fArgs);
+                ByteBuffer result = finalFunction.execute(protocolVersion, fArgs);
+                return result;
             }
 
             public void reset()
             {
                 state = initcond != null ? initcond.duplicate() : null;
+                stateFunctionDuration = 0;
+                stateFunctionCount = 0;
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e651fdd5/src/java/org/apache/cassandra/cql3/functions/UDFunction.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/functions/UDFunction.java b/src/java/org/apache/cassandra/cql3/functions/UDFunction.java
index ab92232..1e5cea6 100644
--- a/src/java/org/apache/cassandra/cql3/functions/UDFunction.java
+++ b/src/java/org/apache/cassandra/cql3/functions/UDFunction.java
@@ -34,6 +34,7 @@ import org.apache.cassandra.cql3.*;
 import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.exceptions.*;
 import org.apache.cassandra.service.MigrationManager;
+import org.apache.cassandra.tracing.Tracing;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 /**
@@ -140,7 +141,11 @@ public abstract class UDFunction extends AbstractFunction implements
ScalarFunct
 
         if (!isCallableWrtNullable(parameters))
             return null;
-        return executeUserDefined(protocolVersion, parameters);
+
+        long tStart = System.nanoTime();
+        ByteBuffer result = executeUserDefined(protocolVersion, parameters);
+        Tracing.trace("Executed UDF {} in {}\u03bcs", name(), (System.nanoTime() - tStart)
/ 1000);
+        return result;
     }
 
     public boolean isCallableWrtNullable(List<ByteBuffer> parameters)


Mime
View raw message