bigdata4u / spymemcached

Automatically exported from code.google.com/p/spymemcached
0 stars 0 forks source link

OutOfMemeryError when server is unreachable #235

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I'm doing a test with a memcached server down.
So the client start to put value in cache in async way, and I want to use the 
async way.
But early I obtain an OutOfMemoryError, even if I create a 
DefaultConnectionFactory with a queue of 10.
If I debug the process in the moment of the error I can see thousand of items 
in the client queue.

Original issue reported on code.google.com by mauri.me...@gmail.com on 19 Feb 2012 at 3:58

GoogleCodeExporter commented 8 years ago
which queue?  can you include you're test?

Original comment by ingen...@gmail.com on 19 Feb 2012 at 5:00

GoogleCodeExporter commented 8 years ago
Here is the source fragment:

ConnectionFactory connectionFactory = new DefaultConnectionFactory(10, 1000000);
List<InetSocketAddress> addresses = new ArrayList<InetSocketAddress>();
addresses.add(new InetSocketAddress("10.3.6.238", 11111));
MemcachedClient mc = new MemcachedClient(connectionFactory, addresses);
long t0 = System.nanoTime();
for (int i = 0; i < N; ++i) {
    try {
        String key = evalKey(i);
        data.replace(0, key.length(), key);
        mc.set(key, 3600, data.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
mc.waitForQueues(10, TimeUnit.MINUTES);
dt = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t0);
System.out.println("Time to insert " + N + " entries: " + dt + " millis");

The queue is the "writeQ" if I see correctly.

Original comment by mauri.me...@gmail.com on 19 Feb 2012 at 5:03

GoogleCodeExporter commented 8 years ago
also, which version?

Original comment by ingen...@gmail.com on 19 Feb 2012 at 5:07

GoogleCodeExporter commented 8 years ago
the last one: 2.8.0 

Original comment by mauri.me...@gmail.com on 19 Feb 2012 at 5:33

GoogleCodeExporter commented 8 years ago
If I can suggest in

net.spy.memcached.MemcachedConnection.addOperation(String, Operation)

at line: 667

      if (placeIn == null) {
        placeIn = primary;
        this.getLogger().warn(
            "Could not redistribute "
                + "to another node, retrying primary node for %s.", key);
      }

at this point i would like to have the possibility to cancel the operation if I 
can't find alternative node to primary.
What do you think about? 

Original comment by mauri.me...@gmail.com on 20 Feb 2012 at 7:00

GoogleCodeExporter commented 8 years ago
That's an option already by configuring the client to not redistribute. There's 
an option for cancellation.  See the ConnectionFactoryBuilder and it's usage 
for details.

Original comment by ingen...@gmail.com on 20 Feb 2012 at 7:09

GoogleCodeExporter commented 8 years ago
I want redistribute the key, but if no alternative node is available or 
connected and primary is unavailable too then I want to cancel the operation.

Original comment by mauri.me...@gmail.com on 20 Feb 2012 at 8:02

GoogleCodeExporter commented 8 years ago
That is the behavior of the client.  If there is no alternative and the primary 
is unavailable, cancellation isn't necessary as the operation won't be sent 
anywhere else.  It'll generate garbage, but that garbage will be cleaned up.

Original comment by ingen...@gmail.com on 16 Mar 2012 at 5:12

GoogleCodeExporter commented 8 years ago
In this moment with a stress test the garbage is not cleaned up and the client 
crash with an OutOfMemeryError. Try the test I attached.

Original comment by mauri.me...@gmail.com on 16 Mar 2012 at 6:22