Last active
August 29, 2015 14:03
-
-
Save kurorido/f68160117403a4298add to your computer and use it in GitHub Desktop.
Insert 1M records into Couchbase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void prepareCouchBase() { | |
print("Testing Insert CouchBase"); | |
CouchClient _dbclient; | |
CouchClient.connect([Uri.parse("http://10.1.4.112:8091/pools")], "default", "").then((CouchClient c) { | |
_dbclient = c; | |
}).then((_) { | |
int startTime = new DateTime.now().millisecondsSinceEpoch; | |
List<Future> futures = new List(); | |
for (var i = 0; i < 1000000; i++) { | |
String key = i.toString(); | |
String name = "name" + i.toString(); | |
String desc = "desc" + i.toString(); | |
List obj = [key, name, desc]; | |
futures.add(_dbclient.add(key, UTF8.encode(JSON.encode(obj)))); // or set? | |
} | |
return Future.wait(futures).then((_) { | |
int endTime = new DateTime.now().millisecondsSinceEpoch; | |
int timeCost = endTime - startTime; | |
print(timeCost.toString() + "ms"); | |
}); | |
}).whenComplete(() { | |
_dbclient.close(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment