Java

1.7 and UP.

It uses NIO File channels for cache write backs to disk. Hence dependency on 1.7.

Github location

https://github.com/dreamdbvilas/wonderdb

Design and How it works

WonderDB cache can be configured as Btree+ index or hash index. Please refer to my blog on Btree+ and Hash Index to understand how both these data structures work in general and how they are used in WonderDB.

Downloading Server and Client

Download bundled server jar file from maven repo
1. Go to maven central on your browser; http://search.maven.org
2. Search for "wonderdb" in search box; You will see 0.3 Latest version under artifact "wondered"
3.Download "wonderdb.jar" from download column.
Download server.properties
1. Go to github; https://github.com/dreamdbvilas/wonderdb
2. Get server.properties file. You will see it on the same page. Click on it and copy it to desired folder.
Download bundled client jar file from maven repo
1. Go to maven central on your browser; http://search.maven.org
2. Search for "wonderdb" in search box. You will see 0.1 latest version of "wonderdbcommandline".
3. Download wondered.jar from Download column

Starting server

Once you have both, the bundled jar and server.properties, you can start the server using following command.

java -cp <jar file name you downloaded in above step> org.wonderdb.WonderDBServer server.properties

Starting client

It needs 2 params machine and port. Default port is 6060. You can change it in server.properties for server if you need to.

java -cp <downloaded bundled client jar> org.wonderdb.wonderdbcommandline.SimpleClient localhost 6060

Simple Client Server interactions through server

You can give following commands through client.

Simple SQL commands to try with
create table vilas (id int, name string, salary long); 
create table company (id int, name string, department string);

create unique index vilasPK on vilas(id); 

insert into vilas (id, name, salary) values (1, 'vilas', 100);
insert into vilas (id, name) values (2, 'wondered');

select * from vilas;
select * from vilas where id = 1;
select * from vilas where id >= 0;
select * from vilas where id >= 0 and id < 100;
select * from vilas where id > 1;

explain plan select * from vilas;
explain plan select * from vilas where id = 10;
explain plan select * from vilas where id > 10;
explain plan select * from vilas where salary >= 100;

update vilas set salary = 200 where id = 1;

delete vilas where id = 3;
delete vilas where id = 2;

shutdown
Configuration

Default server.properties contents are configured for dev machines with minimum settings for caches. You will need to change values based on available physical memory.

Property Description
primaryCache.maxSize Default value 50000. It means it uses 50000 blocks of JVM memory for caching. Each block is 2048 bytes. So default value will use 50000*2048=100MB of JVM heap. Rule of thumb is to set 50% of JVM heap for primary cache.
primaryCache.highWatermark Default value 49090. It describes when primary cache eviction thread will start evicting entries into the cache. Its value should be about 1% of primaryCache.maxSize.
primaryCache.lowWatermark Default value 49050. It describes when primary cache eviction thread stops evicting. Its value should be 2% of primary cache max size.
secondaryCache.maxSize Default value 50000. It uses 50000 blocks of machine physical memory (Direct ByteBuffer). Each block is 2048 bytes. So default value will use 50000*2048=100MB of machine physical memory outside of JVM heap. Set its value based on available machine physical memory.
secondaryCache.highWatermark Default value 49050. It describes when secondary cache eviction thread will start evicting entries into the cache. Its value should be about 1% of secondaryCache.maxSize.
secondaryCache.lowWatermark Default value 49050. It describes when secondary cache eviction thread stops evicting. Its value should be about 2% of secondary cache max size.
cacheWriter.syncTime Default value 3000 (3 seconds). Its value is set in millisecond. It describes how frequently cache writer thread writes back dirty blocks from secondary cache to the disk.
disk.asyncWriterThreadPool.queueSize Default value 10. It describes number parallel threads cache writer invokes to write secondary cache block to disk. Its value should be set depending on type of disk and number of CPUs the node has.
cache.storage Default value ./cache. It describes location of disk file to store cache entries.
cacheIndex.storage Default value ./cacheIndex. It describes location of disk file to store cache key entries.
cache.type [btree , hash]. Default is btree. Read more about btree. If your queries are mostly PK lookup type then use hash else leave it to btree. We have seen performance improvement of over 100% with hash.
cache.buckets This is used only when cache.type is hash. I am in the process of updating a document explaining calculations for its optimal performance. For now leave it to its default value.

Using it in the code

Downloading JDBC driver

Add following maven POM dependency in your java project.

<dependency>
  <groupId>org.wonderdb</groupId>
  <artifactId>wonderdbjdbcdriver</artifactId>
  <version>0.2</version>
</dependency>
JDBC URL
wonderdb://<machine name>:<port>
Code
public static void main(String[] args) {
  DBDriverManager.registerDriver(new WonderDBDriver());
  Connection connection = DriverManger.getConnection("wondered://localhost:6060");
  PreparedStatement stmt = connection.prepareStatement("select * from vilas");
  ResultSet rs = stmt.executeQuery();
  while (rs.next()) {
    int id = rs.getInt(1);
    String name = rs.getString(2);
    long salary = rs.getLong(3);
  }

  // DML statements; insert, update, delete
  stmt = connection.prepareStatement("insert into vilas (id, name) values (10, 'jdbc')");
  int count = stmt.executeQuery();
  
  connection.close();
}

Shutdown

You can shutdown server through SimpleClient. In SimpleClient prompt just call shutdown

shutdown

Questions?

Post you question on WonderDBCache google group.

Leave a Reply

Your email address will not be published. Required fields are marked *