It looks like you've found a bug and the culprit is setTimeoutMillis().
I rewrote your code a bit to eliminate the unnecessary object churn (Session, RequestOptions and AdhocQuery can all be re-used), and commented out the call to setTimeoutMillis(). Without that setting, it runs fine. See below. <disclaimer> I don't work for MarkLogic any more, but when I did I wrote the XCC code, and the timeout thing specifically. The code may have changed in the meantime, but I doubt it. </disclaimer> Go to the Javadoc for RequestOptions.setTimeoutMillis [1]. Note especially the second sentence: "This is almost certainly not what you want". Using this option drags in some complicated code to implement timed reads. This is not necessary or desirable when you're connecting to MarkLogic locally or across a reliable network. You generally want to rely on the request timeout on the appserver to kill long-running queries. It would appear that using setTimeoutMillis() is causing a socket leak somewhere. You should file a bug with MarkLogic (but don't use it anymore). You probably don't want to use setAutoRetryDelayMillis() either, especially not with such a small value. You're better off staying with the default. In fact, you probably don't need a RequestOptions object at all. Defaults will work fine for the majority of uses. [1] http://developer.marklogic.com/pubs/4.2/javadoc/com/marklogic/xcc/RequestOptions.html#setTimeoutMillis%28int%29 public static void main (String[] args) throws URISyntaxException, XccConfigException, RequestException { ContentSource source = ContentSourceFactory.newContentSource ( new URI ("xcc://admin:admin@localhost:8010/Documents")); Session session = source.newSession (); AdhocQuery query = session.newAdhocQuery ("\"Hello\""); RequestOptions options = new RequestOptions (); // options.setTimeoutMillis (30000); options.setAutoRetryDelayMillis (100); session.setDefaultRequestOptions (options); try { for (int i = 0; i < 1000000; i++) { session.submitRequest (query); if (i % 1000 == 0) System.out.println ("Progress: count=" + i); } } finally { session.close(); } } On Aug 30, 2011, at 12:31 AM, Dale Lowry wrote: > I am running out of file handles doing a series of basic queries to the > server using XCC. Hopefully you can find something simple I'm doing wrong in > the following code. > > public static void main(String[] args) throws URISyntaxException, > XccConfigException, RequestException { > ContentSource source = ContentSourceFactory.newContentSource(new > URI("xcc://root:[email protected]:9001/Documents")); > > for (int i = 0; i < 1000000; i++) { > Session session = source.newSession(); > try { > RequestOptions options = new RequestOptions(); > options.setTimeoutMillis(30000); > options.setAutoRetryDelayMillis(100); > session.setDefaultRequestOptions(options); > > AdhocQuery query = session.newAdhocQuery("\"Hello\""); > session.submitRequest(query); > } > finally { > session.close(); > } > if (i % 1000 == 0) { > LOGGER.info("Progress: count=" + i); > } > } > } > > After about 20k calls I get the too many open files error. > > Thanks. > _______________________________________________ > General mailing list > [email protected] > http://developer.marklogic.com/mailman/listinfo/general --- Ron Hitchens {mailto:[email protected]} Ronsoft Technologies +44 7879 358 212 (voice) http://www.ronsoft.com +1 707 924 3878 (fax) Bit Twiddling At Its Finest "No amount of belief establishes any fact." -Unknown _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
