why using unlimited LinkedBlockingQueue to receive org.apache.tinkerpop.gremlin.driver.Result

123 views
Skip to first unread message

jeremy...@gmail.com

unread,
Aug 31, 2020, 5:13:57 AM8/31/20
to Gremlin-users
when I try to query the sql like "g.V()" which will return super big results and print every result,  OOM happen every time. Then I find that the LinkedBlockingQueue<Result> has lots of items. Does it make OOM?
The related code is located at org.apache.tinkerpop.gremlin.driver.Connection 214.

Thank you

Stephen Mallette

unread,
Sep 2, 2020, 9:23:58 AM9/2/20
to gremli...@googlegroups.com
I suppose you could get an OOM if you did g.V() then realized all the results in memory on your client or perhaps didn't consume the results fast enough somehow (which would help fill the LinkedBlockingQueue). If you're just printing results it seems surprising that you would not be able to print as fast as the results arrived, so I'm not sure why that queue would fill up.

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/43627af5-2984-40e5-81ea-7fae5dd5e9a2n%40googlegroups.com.

jeremy...@gmail.com

unread,
Sep 6, 2020, 10:50:06 PM9/6/20
to Gremlin-users
Thanks for your reply. I'm sure it's the print causes an OOM happened. I just wonder know  if there are other ways can replace the unlimited LinkedBlockingQueue. Because I don't think it's a good way using the unlimited LinkedBlockingQueue. Thank you again.

Stephen Mallette

unread,
Sep 7, 2020, 6:36:18 AM9/7/20
to gremli...@googlegroups.com
Could you please show the code that is producing this problem? 

> Because I don't think it's a good way using the unlimited LinkedBlockingQueue.

What are you suggesting? Should it be changed to a bounded queue of some sort? Something else?

jeremy...@gmail.com

unread,
Sep 8, 2020, 3:33:04 AM9/8/20
to Gremlin-users
Why I don't think it's a good way just because it can cause OOM. I've tried to change it to be a bounded queue. And it's slower than the raw way. Besides, I can't find more ways to replace that for now. Here is the code and the pictures of memory analysis when OOM happened.
1.png
2.png3.png

Stephen Mallette

unread,
Sep 8, 2020, 6:34:43 AM9/8/20
to gremli...@googlegroups.com
Sorry - when I asked for code, I was asking to see the code that you were executing that produces the OOM. Could you please include that?

jeremy...@gmail.com

unread,
Sep 8, 2020, 10:18:55 PM9/8/20
to Gremlin-users
yes, I just executed g.V().valueMap(true), and I had about 20 million vertices. I gave JVM arguments -Xms512m -Xmx2g.

Stephen Mallette

unread,
Sep 9, 2020, 6:25:55 AM9/9/20
to gremli...@googlegroups.com
There are lots of ways to execute g.V().valueMap(true) - i think you said you were printing them out. Could you please provide a complete code example?

jeremy...@gmail.com

unread,
Sep 9, 2020, 11:20:33 PM9/9/20
to Gremlin-users
sure, here you are.

ResultSet resultSet = client.submit("g.V().valueMap(true)");
Iterator<Result> iterator;
if (iterator == null || !iterator.hasNext())
{
List<Result> results = null;
try
{
results = resultSet.some(10).join();
}
iterator = results.iterator();
if (iterator.hasNext())
{
System.out.println(iterator.next());

jeremy...@gmail.com

unread,
Sep 14, 2020, 11:39:23 PM9/14/20
to Gremlin-users
Is there something found?

Stephen Mallette

unread,
Sep 15, 2020, 3:22:15 PM9/15/20
to gremli...@googlegroups.com
So, I guess it is as I said earlier - the results may not be consumed from the queue at the rate they come in which can lead to an OOME. I didn't realize how fast it filled with a simple println though. Interesting. For now, I can only suggest that you increase your -Xmx to support both the queue size and results you expect to hold in memory. 

I did a rough hack at bounding the queue to 100,000 and it nicely processed about a billion results with -Xmx512m and no OOME. I'm not sure that my "rough hack" is the "right" way to go though - created an issue for further discussion:




On Mon, Sep 14, 2020 at 11:39 PM jeremy...@gmail.com <jeremy...@gmail.com> wrote:
Is there something found?

在2020年9月10日星期四 UTC+8 上午11:20:33<jeremy...@gmail.com> 写道:
sure, here you are.

ResultSet resultSet = client.submit("g.V().valueMap(true)");
Iterator<Result> iterator;
if (iterator == null || !iterator.hasNext())
{
List<Result> results = null;
try
{
results = resultSet.some(10).join();
}
iterator = results.iterator();
if (iterator.hasNext())
{
System.out.println(iterator.next());
}
}

在2020年9月9日星期三 UTC+8 下午6:25:55<spmal...@gmail.com> 写道:
There are lots of ways to execute g.V().valueMap(true) - i think you said you were printing them out. Could you please provide a complete code example?

On Tue, Sep 8, 2020 at 10:19 PM jeremy...@gmail.com <jeremy...@gmail.com> wrote:
yes, I just executed g.V().valueMap(true), and I had about 20 million vertices. I gave JVM arguments -Xms512m -Xmx2g.
在2020年9月8日星期二 UTC+8 下午6:34:43<spmal...@gmail.com> 写道:
Sorry - when I asked for code, I was asking to see the code that you were executing that produces the OOM. Could you please include that?

On Tue, Sep 8, 2020 at 3:33 AM jeremy...@gmail.com <jeremy...@gmail.com> wrote:
Why I don't think it's a good way just because it can cause OOM. I've tried to change it to be a bounded queue. And it's slower than the raw way. Besides, I can't find more ways to replace that for now. Here is the code and the pictures of memory analysis when OOM happened.

jeremy...@gmail.com

unread,
Sep 22, 2020, 9:27:36 PM9/22/20
to Gremlin-users
If Using a bounded queue, the followed code in org.apache.tinkerpop.gremlin.driver.ResultQueue should be noticed. Because offer() will abandon items when the queue is full.
public void add(final Result result) {
        this.resultLinkedBlockingQueue.offer(result);
        tryDrainNextWaiting(false);
    }

Stephen Mallette

unread,
Sep 23, 2020, 6:55:08 AM9/23/20
to gremli...@googlegroups.com
agreed - that's why my hack (shown in the diff on the JIRA issue) puts offer() in a while loop :/

Reply all
Reply to author
Forward
0 new messages