Skip to content

Commit

Permalink
DX-24414: Make gandiva cache size configurable (apache#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
projjal committed Aug 20, 2020
1 parent 5598bc6 commit f876e56
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
27 changes: 25 additions & 2 deletions cpp/src/gandiva/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#pragma once

#include <cstdlib>
#include <iostream>
#include <mutex>

#include "gandiva/lru_cache.h"
Expand All @@ -26,7 +28,12 @@ namespace gandiva {
template <class KeyType, typename ValueType>
class Cache {
public:
explicit Cache(size_t capacity = CACHE_SIZE) : cache_(capacity) {}
explicit Cache(size_t capacity) : cache_(capacity) {
std::cout << "Creating gandiva cache with capacity: " << capacity << std::endl;
}

Cache() : Cache(GetCapacity()) {}

ValueType GetModule(KeyType cache_key) {
arrow::util::optional<ValueType> result;
mtx_.lock();
Expand All @@ -42,8 +49,24 @@ class Cache {
}

private:
static int GetCapacity() {
int capacity;
const char* env_cache_size = std::getenv("GANDIVA_CACHE_SIZE");
if (env_cache_size != nullptr) {
capacity = std::atoi(env_cache_size);
if (capacity <= 0) {
std::cout << "Invalid cache size provided. Using default cache size."
<< std::endl;
capacity = DEFAULT_CACHE_SIZE;
}
} else {
capacity = DEFAULT_CACHE_SIZE;
}
return capacity;
}

LruCache<KeyType, ValueType> cache_;
static const int CACHE_SIZE = 250;
static const int DEFAULT_CACHE_SIZE = 500;
std::mutex mtx_;
};
} // namespace gandiva
2 changes: 2 additions & 0 deletions cpp/src/gandiva/lru_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#pragma once

#include <list>
#include <iostream>
#include <unordered_map>
#include <utility>

Expand Down Expand Up @@ -107,6 +108,7 @@ class LruCache {

private:
void evict() {
std::cout << "Evicted a cache item from the lru cache" << std::endl;
// evict item from the end of most recently used list
typename list_type::iterator i = --lru_list_.end();
map_.erase(*i);
Expand Down
8 changes: 6 additions & 2 deletions dev/tasks/gandiva-jars/build-cpp-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ PIP="${CPYTHON_PATH}/bin/pip"
ARROW_BUILD_DIR=/tmp/arrow-build
mkdir -p "${ARROW_BUILD_DIR}"
pushd "${ARROW_BUILD_DIR}"
ls /tmp/arrow-build

PATH="${CPYTHON_PATH}/bin:${PATH}"

cmake -DCMAKE_BUILD_TYPE=Release \
cmake -DCMAKE_BUILD_TYPE=Debug \
-DARROW_DEPENDENCY_SOURCE="SYSTEM" \
-DZLIB_ROOT=/usr/local \
-DCMAKE_INSTALL_PREFIX=/arrow-dist \
Expand Down Expand Up @@ -63,9 +64,12 @@ cmake -DCMAKE_BUILD_TYPE=Release \
-DBOOST_ROOT=/arrow_boost_dist \
-GNinja /arrow/cpp
ninja install
ninja test

ls ./debug
cp ./debug/gandiva-precompiled-test /io/dist
popd


# copy the library to distribution
cp -L /arrow-dist/lib/libgandiva_jni.so /io/dist
cp -L /arrow-dist/lib/libarrow.so.100.0.0 /io/dist
3 changes: 1 addition & 2 deletions dev/tasks/gandiva-jars/build-cpp-osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pushd cpp
-DARROW_GANDIVA=ON \
-DARROW_GANDIVA_JAVA=ON \
-DARROW_GANDIVA_STATIC_LIBSTDCPP=ON \
-DARROW_BUILD_TESTS=ON \
-DARROW_BUILD_TESTS=OFF \
-DARROW_BUILD_UTILITIES=OFF \
-DPARQUET_BUILD_ENCRYPTION=OFF \
-DARROW_PARQUET=OFF \
Expand All @@ -44,7 +44,6 @@ pushd cpp

cmake $CMAKE_FLAGS ..
make -j4
ctest

cp -L release/libgandiva_jni.dylib $TRAVIS_BUILD_DIR/dist
popd
Expand Down
6 changes: 2 additions & 4 deletions dev/tasks/gandiva-jars/build-java.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ pushd java
fi

# build the entire project
mvn clean install -q -DskipTests -P arrow-jni -Darrow.cpp.build.dir=$CPP_BUILD_DIR
# test only gandiva
mvn test -q -P arrow-jni -pl gandiva -Dgandiva.cpp.build.dir=$CPP_BUILD_DIR

mvn clean install -DskipTests -P arrow-jni -Darrow.cpp.build.dir=$CPP_BUILD_DIR

# copy the jars to distribution folder
find gandiva/target/ -name "*.jar" -not -name "*tests*" -exec cp {} $CPP_BUILD_DIR \;
popd
3 changes: 1 addition & 2 deletions dev/tasks/gandiva-jars/travis.linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ script:
- mkdir -p dist
# please refer to README for steps to update this image
- docker run -v $PWD:/io -v $PWD:/arrow quay.io/prudhvi/arrow:buildGandivaDocker /io/dev/tasks/gandiva-jars/build-cpp-linux.sh || travis_terminate 1
- dev/tasks/gandiva-jars/build-java.sh || travis_terminate 1
# deploy using crossbow
- >
python3 dev/tasks/crossbow.py
Expand All @@ -69,4 +68,4 @@ script:
upload-artifacts
--sha {{ task.branch }}
--tag {{ task.tag }}
--pattern "dist/*.jar"
--pattern "dist/libarrow.so.100.0.0"

0 comments on commit f876e56

Please sign in to comment.