view src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/mongo/PerformanceComparisonJungleMongo.java @ 26:96fcae37c62a

fix mongoBenchMark
author tatsuki
date Mon, 04 May 2015 00:38:57 +0900
parents 69dca2ab1783
children
line wrap: on
line source

package jp.ac.u_ryukyu.ie.cr.tatsuki.mongo;

import com.mongodb.MongoClient;
import com.mongodb.WriteConcern;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import jp.ac.u_ryukyu.cr.ie.tatsuki.xmlTestBbs.JuGrix;
import jp.ac.u_ryukyu.ie.cr.tatsuki.xml.extendXmlTree;
import org.bson.Document;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import java.util.Arrays;

/**
 * Created by e115731 on 15/05/02.
 */
public class PerformanceComparisonJungleMongo {

    public static void main(String args[]) throws IOException, InterruptedException, ParserConfigurationException, SAXException {
        if (args.length < 1)
            System.out.println("args[0] = mongo or jungle");

        if (args[0].equals("mongo"))
            PerformanceCheckMongo();
        else if (args[0].equals("jungle"))
            PerformanceCheckJungle();
        System.out.println("end");
    }

    private static void PerformanceCheckJungle() throws ParserConfigurationException, IOException, SAXException, InterruptedException {
        File file = new File("./time/jungleBenchMark");
        PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
        for (int count = 100; count <= 1000; count = 50 + count) {
            JuGrix jugrix = extendXmlTree.createJuGrix(true, count);

            long t1 = System.currentTimeMillis();
            for (int readCount = 0 ; readCount < 10000000;readCount++) {
                boolean account = jugrix.isActive("p:" + 100, "v:1");
            }
            long t2 = System.currentTimeMillis();
            long readTime = t2 - t1;
            pw.println(count + " = " + readTime);
            System.out.println("readTime = " + readTime);
        }
        pw.close();
    }


    private static void PerformanceCheckMongo() throws InterruptedException, IOException {
        MongoClient client = new MongoClient("localhost", 27017);
        File file = new File("./time/mongoBenchMark");
        PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
        for (int count = 100; count <= 1000; count = 50 + count) {
            client.setWriteConcern(WriteConcern.JOURNALED);
            client.dropDatabase("mydb");
            MongoDatabase database = client.getDatabase("mydb");
            MongoCollection<Document> coll = database.getCollection("Persons");
            for (int personCount = 0; personCount < count; personCount++) {
                Document person = new Document("Personid", "p:" + String.valueOf(personCount))
                        .append("type", "Person")
                        .append("accountId", "a:" + String.valueOf(personCount))
                        .append("lastName", "金川").append("name", "金川竜己")
                        .append("nameReading", "かながわたつきくん")
                        .append("roleRefIds"
                                , new Document("roleRefId", "r:3")
                                .append("roleRefId", "r:3"))
                        .append("parentOrganizations"
                                , new Document("type", "OrganizationMappedByRole")
                                        .append("OrganizationMappedByRole",
                                                Arrays.asList(
                                                        new Document("type", "OrganizationMappedByRole")
                                                                .append("organizationRefId", "o:2")
                                                                .append("roleRefId", "r:10")
                                                        , new Document("type", "OrganizationMappedByRole")
                                                                .append("organizationRefId", "o:4")
                                                                .append("roleRefId", "r:14")))
                        ).append("priorities",
                                new Document("type", "PriorityMappedByRole")
                                        .append("PriorityMappedByRole"
                                                , Arrays.asList(
                                                new Document("type", "PriorityMappedByRole")
                                                        .append("priority", "0")
                                                        .append("roleRefId", "r:10")
                                                , new Document("type", "PriorityMappedByRole")
                                                        .append("priority", "1")
                                                        .append("roleRefId", "r:14")))
                        );
                coll.insertOne(person);
            }
            coll.createIndex(new Document("Personid", 1));
            System.out.println("insertEnd");
            ReadMongoThread th = new ReadMongoThread(coll);
            th.start();
            Thread.sleep(10000);
            th.set(false);
            int findCount = th.getFindCount();
            System.out.println("findCount = " + findCount);
            pw.println(count + " " + findCount);
        }
        pw.close();
    }
}