我正在尝试从IBM Domino v9.0收集帐户数据和组数据。
我为收集数据而编写的代码使用了lotus.domino.View API。代码适用于小型数据集,我运行 40个用户的代码,这很好。当我运行代码以提取 10k用户的数据时,大约需要 3-4小时来提取数据,这是不可接受的。
您能否建议我使用其他API来更快地检索数据?
我目前使用的代码如下:
private static void testUserDataRetrieval(String host, String userName, String password) throws Exception{
Session s = NotesFactory.createSession(host, userName, password);
Database db = s.getDatabase(s.getServerName(), "names");
File outFile = new File("C:\\Users\\vishva\\Desktop\\dominoExtract.txt");
FileWriter writer = new FileWriter(outFile);
View view = db.getView("($Users)");
ViewEntryCollection entryCollection = view.getAllEntries();
writer.write("\n--------------------------------- Printing data for view:"+view.getName()+"("+view.getEntryCount()+")--------------------------------------------");
Vector<Object> columnNames = view.getColumnNames();
for(int i = 0; i< entryCollection.getCount(); i++){
ViewEntry entry = entryCollection.getNextEntry();
if(entry == null) continue;
Vector<Object> colValues = entry.getColumnValues();
for(int j = 0; j < columnNames.size(); j++)
writer.write("\n"+columnNames.get(j)+":"+colValues.get(j));
writer.write("\n*****************************************");
}
writer.flush();
writer.close();
}
请告诉我应该使用哪个其他API来提高数据检索的速度?
答案 0 :(得分:2)
首先:您在for循环的每次运行中读取集合的计数。这使得它非常慢。完全不需要for循环。第二:你永远不会回收对象。当使用多米诺骨牌对象时,这就是强制性的,否则你的代码会比你想象的更快地耗尽内存:
private static void testUserDataRetrieval(String host, String userName, String password) throws Exception{
Session s = NotesFactory.createSession(host, userName, password);
Database db = s.getDatabase(s.getServerName(), "names");
File outFile = new File("C:\\Users\\vishva\\Desktop\\dominoExtract.txt");
FileWriter writer = new FileWriter(outFile);
View view = db.getView("($Users)");
ViewEntryCollection entryCollection = view.getAllEntries();
writer.write("\n--------------------------------- Printing data for view:"+view.getName()+"("+view.getEntryCount()+")--------------------------------------------");
Vector<Object> columnNames = view.getColumnNames();
ViewEntry entry = entryCollection.getFirstEntry();
ViewEntry entryNext;
while(entry != null) {
Vector<Object> colValues = entry.getColumnValues();
for(int j = 0; j < columnNames.size(); j++)
writer.write("\n"+columnNames.get(j)+":"+colValues.get(j));
writer.write("\n*****************************************");
entryNext = entryCollection.getNextEntry();
entry.recycle();
entry = entryNext ;
}
writer.flush();
writer.close();
}
答案 1 :(得分:1)
默认情况下,View对象的isAutoUpdate属性设置为true。这意味着它是synchronizing,后端正在发生任何更改,而不仅仅是为您提供一次性快照。加上这个:
view.setAutoUpdate(false);
此外,您应该调查使用ViewNavigator类。有关详细说明自Domino 8.5.2起此类中性能改进的文章,请参阅here。它由类的主要开发人员编写。另请参阅此blog post以获取许多有趣的细节。
答案 2 :(得分:0)
感谢大家的投入。 为了检索用户,我稍后尝试了LDAP API,它就像魅力一样。我能够在 23秒中检索 10k帐户,这是可以接受的。我使用的代码如下
private void extractDominoDataViaLdap(){
String [] args = new String[]{"192.168.21.156","Administrator","password","","C:\\Users\\vishva\\Desktop"};
String server = args[0];
String userName = args[1];
String password = args[2];
String baseDN = args[3];
String fileLocation = args[4];
// Set up environment for creating initial context
Hashtable<String, Object> env = new Hashtable<String, Object>(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://"+server+":389");
long time = System.currentTimeMillis();
// Authenticate as S. User and password "mysecret"
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, userName);
env.put(Context.SECURITY_CREDENTIALS, password);
FileWriter writer = null;
BufferedWriter out = null;
try {
DirContext ctx = new InitialDirContext(env);
//fetching user data
// Create the search controls
SearchControls searchCtls = new SearchControls();
// Specify the attributes to return
String returnedAtts[] = {"FullName","dn","displayname","givenName","sn","location","mail","mailfile","mailserver"};
searchCtls.setReturningAttributes(returnedAtts);
// Specify the search scope
searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
searchCtls.setCountLimit(0);
// specify the LDAP search filter
String searchFilter = "objectClass=inetOrgPerson";
// Specify the Base for the search
String searchBase = baseDN;
// Search for objects using the filter
NamingEnumeration<SearchResult> answer = ctx.search(searchBase,searchFilter, searchCtls);
writer = new FileWriter(fileLocation+"\\users.csv");
out = new BufferedWriter(writer);
for(String attr : returnedAtts)
out.write(attr+",");
out.write("\n");
int count = 0;
// Loop through the search results
while (answer.hasMoreElements()) {
++count;
SearchResult sr = (SearchResult) answer.next();
Attributes attrs = sr.getAttributes();
StringBuilder sb = new StringBuilder();
for(String attr : returnedAtts)
sb.append("\""+((attrs.get(attr) != null)?attrs.get(attr).get():"")+"\"").append(",");
out.write(sb.toString()+"\n");
out.flush();
}
System.out.println("# of users returned: "+count);
out.close();
writer.close();
}
}