Mercurial > hg > Members > tatsuki > jungle-bench
changeset 5:24fca21a576e
add Read thread source
author | Kanagawa TATSUKI <tatsuki@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 30 Mar 2014 23:21:59 +0900 |
parents | 671a67571a48 |
children | 6954add9eea9 |
files | src/main/java/example/SimpleJungleRead.java src/main/java/example/SimplejungleMalti.java src/main/java/example/WriteThread.java |
diffstat | 3 files changed, 129 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/example/SimpleJungleRead.java Sun Mar 30 23:21:59 2014 +0900 @@ -0,0 +1,126 @@ +package example; + +import java.nio.ByteBuffer; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; +import junit.framework.Assert; + + +public class SimpleJungleRead extends Thread { + public static final String key = "name"; + public static final String valueString = "kanagawsa"; + public static final ByteBuffer value = ByteBuffer.wrap(valueString.getBytes()); + + public static void main(String[] args) { + System.out.println("タスク数"+args[0]); + System.out.println("CPU数"+args[1]); + int roopCount = Integer.parseInt(args[0]); + int threadCount = Integer.parseInt(args[1]); + + WriteThread[] wt = new WriteThread[threadCount]; + Jungle j = new DefaultJungle(null, "hogehoge", new DefaultTreeEditor(new DefaultTraverser())); + j.createNewTree("tree");// 木を作った + JungleTree tree = j.getTreeByName("tree");// 名前を取得 + JungleTreeEditor editor1 = tree.getTreeEditor();// editorの取得 + NodePath root = new DefaultNodePath();// パスの取得 + + // eitherに値を入れる + Either<Error, JungleTreeEditor> either = editor1.putAttribute(root,key, value); + if (either.isA()) {// 失敗した場合Aが出てくる + Assert.fail(); + } + editor1 = either.b(); + editor1.success(); + // ここで初めてSUCCESS + + Node node = tree.getRootNode(); + ByteBuffer v = node.getAttributes().get(key); + System.out.println(new String(v.array())); + + // ------以下子ノードの値変更 + editor1 = tree.getTreeEditor();// Treeのeditorを作成 + either = editor1.addNewChildAt(root, 0);// 新しく入れるところへのパス + if (either.isA()) {// ちゃんとパスを指定できたかチェック + Assert.fail(); + } + editor1 = either.b();// 成功した場合パスを入れる + NodePath childPath = root.add(0); + either = editor1.success(); + if (either.isA()) {// ちゃんとパスを指定できたかチェック + Assert.fail(); + } + // そしてここで子ノードに値を入れる + + long t1 = System.currentTimeMillis();// 時間の測定開始 + for (int count = 0; count < threadCount; count++) { + wt[count] = new WriteThread(j, childPath, + (roopCount / threadCount), count); + } + for (int count = 0; count < threadCount; count++) { + wt[count].start(); + } + + for (int count = 0; count < threadCount; count++) { + try { + wt[count].join(); + } catch (InterruptedException e) { + } + } + + long t2 = System.currentTimeMillis(); + System.out.println(t2 - t1 + "s"); + + node = tree.getRootNode(); + Children<Node> children = node.getChildren(); + Either<Error, Node> either2 = children.at(0); + if (either2.isA()) { + Assert.fail(); + } + + Node childNode = either2.b(); + ByteBuffer v2 = childNode.getAttributes().get(key); + System.out.println(new String(v2.array())); + } + + + public static DefaultTreeNode factory = new DefaultTreeNode(new DefaultNode()); + + public DefaultTreeNode createTree(int _curX,int _curY,int _maxHeight,NodePath _address) + { + DefaultTreeNode parent = factory.createNewNode(); + Either<Error,DefaultTreeNode> either = parent.getAttributes().put(key,ByteBuffer.wrap(_address.toString().getBytes())); + if(either.isA()){ + Assert.fail(); + } + parent = either.b(); + + if(_curY == _maxHeight){ + return parent; + } + + for(int i = 0;i < _curY + 1;i ++){ + DefaultTreeNode ch = createTree(i,_curY + 1,_maxHeight,_address.add(i)); + either = parent.getChildren().addNewChildAt(i,ch); + if(either.isA()){ + Assert.fail(); + } + + parent = either.b(); + } + + return parent; + } +}
--- a/src/main/java/example/SimplejungleMalti.java Thu Mar 06 05:08:24 2014 +0900 +++ b/src/main/java/example/SimplejungleMalti.java Sun Mar 30 23:21:59 2014 +0900 @@ -49,7 +49,7 @@ ByteBuffer v = node.getAttributes().get(key); System.out.println(new String(v.array())); - // ------以下子ノードの値変更 + // ------以下子ノードの作成 editor1 = tree.getTreeEditor();// Treeのeditorを作成 either = editor1.addNewChildAt(root, 0);// 新しく入れるところへのパス if (either.isA()) {// ちゃんとパスを指定できたかチェック
--- a/src/main/java/example/WriteThread.java Thu Mar 06 05:08:24 2014 +0900 +++ b/src/main/java/example/WriteThread.java Sun Mar 30 23:21:59 2014 +0900 @@ -35,7 +35,7 @@ long t1 = System.currentTimeMillis();// 時間の測定開始 for (int count = 0; count < roopCount; count++) { - do{ + do { JungleTreeEditor editor = tree.getTreeEditor();// Treeのeditorを作成 either = editor.putAttribute(childPath, key, value); if (either.isA()) { @@ -43,7 +43,7 @@ } editor = either.b(); either = editor.success(); - }while(either.isA()); + } while (either.isA()); } long t2 = System.currentTimeMillis(); System.out.println(num + "番目終わり" + (t2 - t1) + "秒");