You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/05/16 16:45:32 UTC

[GitHub] [arrow] andygrove opened a new pull request #7205: ARROW-8782: [Rust] Add benchmark crate

andygrove opened a new pull request #7205:
URL: https://github.com/apache/arrow/pull/7205


   This PR adds a new crate for benchmarks based on the [New York Taxi and Limousine Commission](https://www1.nyc.gov/site/tlc/about/tlc-trip-record-data.page) data set.
   
   Currently, only DataFusion benchmarks exist, but the plan is to add benchmarks for the arrow, flight, and parquet crates as well.
   
   Example usage:
   
   ```bash
   cargo run --release -- --iterations 3 --path /mnt/nyctaxi/csv --format csv --batch-size 4096
   ```
   
   Example output:
   
   ```bash
   Running benchmarks with the following options: Opt { debug: false, iterations: 3, batch_size: 4096, path: "/mnt/nyctaxi/csv", file_format: "csv" }
   Executing 'fare_amt_by_passenger'
   Query 'fare_amt_by_passenger' iteration 0 took 7138 ms
   Query 'fare_amt_by_passenger' iteration 1 took 7599 ms
   Query 'fare_amt_by_passenger' iteration 2 took 7969 ms
   ```
   
   Follow-up PRs will add additional functionality, such as:
   
   - Storing results in structured files (json perhaps)
   - Adding a Dockerfile so that the benchmarks can be run with CPU and RAM constraints


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] wesm closed pull request #7205: ARROW-8782: [Rust] Add benchmark crate

Posted by GitBox <gi...@apache.org>.
wesm closed pull request #7205:
URL: https://github.com/apache/arrow/pull/7205


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] andygrove commented on a change in pull request #7205: ARROW-8782: [Rust] Add benchmark crate

Posted by GitBox <gi...@apache.org>.
andygrove commented on a change in pull request #7205:
URL: https://github.com/apache/arrow/pull/7205#discussion_r428885121



##########
File path: rust/benchmarks/src/main.rs
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Apache Arrow Rust Benchmarks
+
+use std::collections::HashMap;
+use std::path::PathBuf;
+use std::process;
+use std::time::Instant;
+
+use arrow::datatypes::{DataType, Field, Schema};
+use arrow::util::pretty;
+use datafusion::error::Result;
+use datafusion::execution::context::ExecutionContext;
+
+use structopt::StructOpt;
+
+#[derive(Debug, StructOpt)]
+#[structopt(name = "Benchmarks", about = "Apache Arrow Rust Benchmarks.")]
+struct Opt {
+    /// Activate debug mode to see query results
+    #[structopt(short, long)]
+    debug: bool,
+
+    /// Number of iterations of each test run
+    #[structopt(short = "i", long = "iterations", default_value = "3")]
+    iterations: usize,
+
+    /// Batch size when reading CSV or Parquet files
+    #[structopt(short = "s", long = "batch-size", default_value = "4096")]
+    batch_size: usize,
+
+    /// Path to data files
+    #[structopt(parse(from_os_str), required = true, short = "p", long = "path")]
+    path: PathBuf,
+
+    /// File format: `csv` or `parquet`
+    #[structopt(short = "f", long = "format", default_value = "csv")]
+    file_format: String,
+}
+
+fn main() -> Result<()> {
+    let opt = Opt::from_args();
+    println!("Running benchmarks with the following options: {:?}", opt);
+
+    let mut ctx = ExecutionContext::new();
+
+    let path = opt.path.to_str().unwrap();
+
+    match opt.file_format.as_str() {
+        "csv" => ctx.register_csv("tripdata", path, &nyctaxi_schema(), true),
+        "parquet" => ctx.register_parquet("tripdata", path)?,
+        other => {
+            println!("Invalid file format '{}'", other);
+            process::exit(-1);
+        }
+    }
+
+    datafusion_sql_benchmarks(&mut ctx, opt.iterations, opt.batch_size, opt.debug)
+}
+
+fn datafusion_sql_benchmarks(
+    ctx: &mut ExecutionContext,
+    iterations: usize,
+    batch_size: usize,
+    debug: bool,
+) -> Result<()> {
+    let mut queries = HashMap::new();
+    queries.insert("fare_amt_by_passenger", "SELECT passenger_count, MIN(fare_amount), MIN(fare_amount), SUM(fare_amount) FROM tripdata GROUP BY passenger_count");
+    for (name, sql) in &queries {
+        println!("Executing '{}'", name);
+        for i in 0..iterations {
+            let start = Instant::now();
+            execute_sql(ctx, sql, batch_size, debug)?;
+            println!(
+                "Query '{}' iteration {} took {} ms",
+                name,
+                i,
+                start.elapsed().as_millis()
+            );
+        }
+    }
+    Ok(())
+}
+
+fn execute_sql(
+    ctx: &mut ExecutionContext,
+    sql: &str,
+    batch_size: usize,
+    debug: bool,
+) -> Result<()> {
+    let plan = ctx.create_logical_plan(sql)?;
+    let plan = ctx.optimize(&plan)?;
+    if debug {
+        println!("Optimized logical plan:\n{:?}", plan);
+    }
+    let physical_plan = ctx.create_physical_plan(&plan, batch_size)?;
+    let result = ctx.collect(physical_plan.as_ref())?;
+    if debug {
+        pretty::print_batches(&result)?;
+    }
+    Ok(())
+}
+
+fn nyctaxi_schema() -> Schema {

Review comment:
       No, I've just been testing queries against a single year so far and this is the correct schema for that year.
   
   If/when we extend these benchmarks to query across multiple years we would need to improve this. 
   
   DataFusion doesn't yet support schema merging.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] andygrove commented on pull request #7205: ARROW-8782: [Rust] Add benchmark crate

Posted by GitBox <gi...@apache.org>.
andygrove commented on pull request #7205:
URL: https://github.com/apache/arrow/pull/7205#issuecomment-634078005






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] github-actions[bot] commented on pull request #7205: ARROW-8782: [Rust] Add benchmark crate

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #7205:
URL: https://github.com/apache/arrow/pull/7205#issuecomment-629673929


   https://issues.apache.org/jira/browse/ARROW-8782


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] nevi-me commented on pull request #7205: ARROW-8782: [Rust] Add benchmark crate

Posted by GitBox <gi...@apache.org>.
nevi-me commented on pull request #7205:
URL: https://github.com/apache/arrow/pull/7205#issuecomment-631050794


   Would the idea be to centralise benchmarks from the other crates?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] wesm commented on pull request #7205: ARROW-8782: [Rust] Add benchmark crate

Posted by GitBox <gi...@apache.org>.
wesm commented on pull request #7205:
URL: https://github.com/apache/arrow/pull/7205#issuecomment-634165274


   @andygrove CI is broken since it appears there was an API change since the CI last ran on this patch, wanted to make sure you were aware


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] fsaintjacques commented on a change in pull request #7205: ARROW-8782: [Rust] Add benchmark crate

Posted by GitBox <gi...@apache.org>.
fsaintjacques commented on a change in pull request #7205:
URL: https://github.com/apache/arrow/pull/7205#discussion_r428859081



##########
File path: rust/benchmarks/src/main.rs
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Apache Arrow Rust Benchmarks
+
+use std::collections::HashMap;
+use std::path::PathBuf;
+use std::process;
+use std::time::Instant;
+
+use arrow::datatypes::{DataType, Field, Schema};
+use arrow::util::pretty;
+use datafusion::error::Result;
+use datafusion::execution::context::ExecutionContext;
+
+use structopt::StructOpt;
+
+#[derive(Debug, StructOpt)]
+#[structopt(name = "Benchmarks", about = "Apache Arrow Rust Benchmarks.")]
+struct Opt {
+    /// Activate debug mode to see query results
+    #[structopt(short, long)]
+    debug: bool,
+
+    /// Number of iterations of each test run
+    #[structopt(short = "i", long = "iterations", default_value = "3")]
+    iterations: usize,
+
+    /// Batch size when reading CSV or Parquet files
+    #[structopt(short = "s", long = "batch-size", default_value = "4096")]
+    batch_size: usize,
+
+    /// Path to data files
+    #[structopt(parse(from_os_str), required = true, short = "p", long = "path")]
+    path: PathBuf,
+
+    /// File format: `csv` or `parquet`
+    #[structopt(short = "f", long = "format", default_value = "csv")]
+    file_format: String,
+}
+
+fn main() -> Result<()> {
+    let opt = Opt::from_args();
+    println!("Running benchmarks with the following options: {:?}", opt);
+
+    let mut ctx = ExecutionContext::new();
+
+    let path = opt.path.to_str().unwrap();
+
+    match opt.file_format.as_str() {
+        "csv" => ctx.register_csv("tripdata", path, &nyctaxi_schema(), true),
+        "parquet" => ctx.register_parquet("tripdata", path)?,
+        other => {
+            println!("Invalid file format '{}'", other);
+            process::exit(-1);
+        }
+    }
+
+    datafusion_sql_benchmarks(&mut ctx, opt.iterations, opt.batch_size, opt.debug)
+}
+
+fn datafusion_sql_benchmarks(
+    ctx: &mut ExecutionContext,
+    iterations: usize,
+    batch_size: usize,
+    debug: bool,
+) -> Result<()> {
+    let mut queries = HashMap::new();
+    queries.insert("fare_amt_by_passenger", "SELECT passenger_count, MIN(fare_amount), MIN(fare_amount), SUM(fare_amount) FROM tripdata GROUP BY passenger_count");
+    for (name, sql) in &queries {
+        println!("Executing '{}'", name);
+        for i in 0..iterations {
+            let start = Instant::now();
+            execute_sql(ctx, sql, batch_size, debug)?;
+            println!(
+                "Query '{}' iteration {} took {} ms",
+                name,
+                i,
+                start.elapsed().as_millis()
+            );
+        }
+    }
+    Ok(())
+}
+
+fn execute_sql(
+    ctx: &mut ExecutionContext,
+    sql: &str,
+    batch_size: usize,
+    debug: bool,
+) -> Result<()> {
+    let plan = ctx.create_logical_plan(sql)?;
+    let plan = ctx.optimize(&plan)?;
+    if debug {
+        println!("Optimized logical plan:\n{:?}", plan);
+    }
+    let physical_plan = ctx.create_physical_plan(&plan, batch_size)?;
+    let result = ctx.collect(physical_plan.as_ref())?;
+    if debug {
+        pretty::print_batches(&result)?;
+    }
+    Ok(())
+}
+
+fn nyctaxi_schema() -> Schema {

Review comment:
       Do you have a normalized dataset?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] andygrove commented on pull request #7205: ARROW-8782: [Rust] Add benchmark crate

Posted by GitBox <gi...@apache.org>.
andygrove commented on pull request #7205:
URL: https://github.com/apache/arrow/pull/7205#issuecomment-632316448


   > Would the idea be to centralise benchmarks from the other crates?
   
   Not really. This is different from the criterion style micro benchmarks since these benchmarks can take a long time to run.
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org