[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Orekit Developers] Work In Progress for thread safety
- To: orekit-developers@orekit.org
- Subject: Re: [Orekit Developers] Work In Progress for thread safety
- From: Thomas Neidhart <thomas.neidhart@gmail.com>
- Date: Fri, 13 Apr 2012 22:57:21 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; bh=6O0FlPr4zAi5UgwYUA0EDgd72oXCD+nARhvAmL143P4=; b=JjtU5TDr0TUWbG4rtUVV6oOxfrxO5CBBMlrjd5P6kifYGcyCnlpIl+5mVGah0eWD7J TChPCA0r4AThYLfiHlmDmjobK2ypkebMcf5+HW/Q+oC6sviya1kV9ZQb091RlphFBBKT UrGrGJVDLLJ+eWaOlEnhzW8ToC7VgP9WIYv+4D4JVUg7o1bV9vbZfGtKl4qiiZNX0/A+ /aMYPTHuAQobygRH8Ijoh40IwljBzMRSDhUESkRADqMdHdFViVbewH1IGdSSuRA8yZpM NjN6FYChDEPB2PlB1TsVCbcrOyICXB2xdCdKg5+lKuZou5rIfpnWkFrV7eFTtG+RNx3K 8wZg==
- In-reply-to: <4F884993.300@c-s.fr>
- References: <20120410192212.52283rhsqtgdbxok@messagerie.si.c-s.fr> <4F874B10.4030002@gmail.com> <4F87DBA8.3040605@c-s.fr> <CAJSjvwvN74kVw-7W6zsMtrheEPVqQ1g2JRr5eZ=Nq9QTjAwmoQ@mail.gmail.com> <4F882B57.7090909@c-s.fr> <4F884993.300@c-s.fr>
- User-agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20120329 Thunderbird/11.0.1
On 04/13/2012 05:43 PM, Luc Maisonobe wrote:
> OK, Issue 89 is now fixed. As part of the fix, I have changed dates
> quantization to use long and set up fixed quantum step to 1 microsecond.
>
> This should avoid overflow, but does not prevent the large number of
> slots and even a large number or calls to the generator 1589 in a test I
> just run!
>
> So there is definitely something to do to avoid this.
Yes, the other case when slots are (unnecessarily) created is related to
the limiting of the range the generator can provide. Adding this fix as
discussed before should fix it (tested it locally).
> While debugging issue 89, it appears preventing extra calls is not
> trivial. We must make sure we don't prevent generating new entries
> before the first existing one or after the last existing one when there
> is still some room for potential new entries before generator end. So we
> have to compare the current first (or last) entry with generator
> boundaries and then decide what to do.
>
> We must also take care that in the general case, slots will be evicted,
> so even if some data at boundary has already been generated, it may have
> been evicted and may have to be generated again.
>
> This may happen for UTC-TAI, as I think it would be more efficient to
> limit the size of the slots to say 1 year, so the search at deepest
> level (in the slot) remains fast.
I have looked into this, and the reason (at least for the UTCScale) that
additional call to the generator are performed is a corner case due to
the neighborSize:
- consider you have 40 entries and a neighborSize of 2
- requesting neighbors for a central date that correspond to the last
entry would require the cache to be further filled, as the request
can not be fulfilled: lastIndex + 2 > cache.size()
- thus the generator is asked for new entries
- the UTCScale Generator can not provide more entries, so there is a
safe-guard in TimeStampedCache.Slot.getNeighbors that reduces
lastIndex to fit the available cache size
The problem is that this check is done at the end of the method, after
requesting the generator. To tackle this, two solution come to my mind:
- do a check at the beginning like this:
// if we request neighbors outside the available limit
// and the last entry is already at the generator bound, adjust
// the index of the first neighbor to return to match the current
// available cache entries without requesting more data, as the
// generator will not be able to provide more data
if (firstNeighbor + neighborsSize > cache.size() &&
getLatest().getDate().compareTo(generator.getLatest()) >= 0) {
// we end up with a non-balanced neighborhood,
// adjust the start point to fit within the cache
firstNeighbor = cache.size() - neighborsSize;
}
similar for the lower bound
- add a method to the generator interface (maybe a bad name, but to
get the idea):
public boolean isSingleShot();
which indicates that the generator is providing all its data in one
shot. The Slot.getNeighbors method does a similar check as before:
// same as above, just do not rely on bounds but use an explicit
// indication from the generator
if (firstNeighbor + neighborsSize > cache.size() &&
generator.isSingleShot()) {
// we end up with a non-balanced neighborhood,
// adjust the start point to fit within the cache
firstNeighbor = cache.size() - neighborsSize;
}
Using this the multi-threading test runs through with only 1 generate call.
Thomas