apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chandnisingh <...@git.apache.org>
Subject [GitHub] incubator-apex-malhar pull request: MLHR-1897 #comment added manag...
Date Tue, 23 Feb 2016 02:05:59 GMT
Github user chandnisingh commented on a diff in the pull request:

    --- Diff: library/src/main/java/com/datatorrent/lib/state/managed/StateTracker.java ---
    @@ -0,0 +1,153 @@
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package com.datatorrent.lib.state.managed;
    +import java.io.IOException;
    +import java.util.Comparator;
    +import java.util.Map;
    +import java.util.PriorityQueue;
    +import java.util.Timer;
    +import java.util.TimerTask;
    +import java.util.concurrent.ConcurrentHashMap;
    +import javax.validation.constraints.NotNull;
    +import org.joda.time.Duration;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import com.google.common.base.Preconditions;
    +import com.datatorrent.api.Component;
    +import com.datatorrent.api.Context;
    + * Tracks the size of state in memory and evicts buckets.
    + */
    +class StateTracker extends TimerTask implements Component<Context.OperatorContext>
    +  //bucket id -> last time the bucket was accessed
    +  private final transient ConcurrentHashMap<Long, Long> bucketAccessTimes = new
    +  private transient PriorityQueue<Map.Entry<Long, Long>> bucketHeap;
    --- End diff --
    From @amberarrow 
    One last suggestion to think about: ConcurrentSkipListSet may work better and also avoid
re-populating and clearing the heap each time since it is thread-safe and maintains sorted
order. Feel free to stay with the current version if you prefer it.
    The synchronization cost is sometimes unavoidable when multiple threads are involved.
For example, TimeBucketAssigner.getTimeBucketFor() is called by all the put, getSync and getAsync
methods and yet has 2 synchronized blocks.

If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.

View raw message