view src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/mongo/PerformanceComparisonJungleMongo.java @ 22:306441e23b8b

add PerformanceComparisonJungleMongo
author tatsuki
date Fri, 01 May 2015 20:29:27 +0900
parents
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.ReadJungleThread;
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.IOException;
import java.util.Arrays;

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

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

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


    }

    private static void PerformanceCheckJungle(Integer personCount) throws ParserConfigurationException, IOException, SAXException, InterruptedException {
        JuGrix jugrix = extendXmlTree.createJuGrix(true, personCount);
        ReadJungleThread readThread = new ReadJungleThread(jugrix);
        readThread.start();
        Thread.sleep(10000);
        readThread.set(false);
        System.out.println("findCount = " + readThread.getFindCount());
    }

    private static void PerformanceCheckMongo(int PersonCount) throws InterruptedException {
        MongoClient client = new MongoClient("localhost", 27017);
        client.setWriteConcern(WriteConcern.JOURNALED);
        client.dropDatabase("mydb");
        MongoDatabase database = client.getDatabase("mydb");
        MongoCollection<Document> coll = database.getCollection("Persons");
        for (int personCount = 0; personCount < Integer.valueOf(PersonCount); 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);
        System.out.println("findCount = " + th.getFindCount());
    }

}