the optimal implementation of n fifo queues in single
play

The optimal implementation of n FIFO-queues in single-level memory. - PowerPoint PPT Presentation

The optimal implementation of n FIFO-queues in single-level memory. Prof. A.V. Sokolov, A.V. Drac IAMR KarRC RAS, Petrozavodsk State University, Petrozavodsk. AMICT 2010 Petrozavodsk. Introduction In many applications there is a problem


  1. The optimal implementation of n FIFO-queues in single-level memory. Prof. A.V. Sokolov, A.V. Drac IAMR KarRC RAS, Petrozavodsk State University, Petrozavodsk. AMICT – 2010 Petrozavodsk.

  2. Introduction In many applications there is a problem of allocation of multiple queues in single-level memory. There are two fundamentally different ways of organizing work with dynamic data structures – consecutive and linked allocation. In the case of sequential presentation all the memory is splitted into several parts and each queue is allocated in separate section of memory. In this case we will have losses of memory when any queue overflow and other data structures don’t overflow. Figure 1: The consecutive implementation The linked list implementation is the second method. In this view the data structure is stored as a list. In this case any number of elements of the lists can coexist in the fast memory area until the free memory is exhausted. But on the other hand, this approach requires an additional link field for each element. Figure 2: The linked list implementation

  3. The problem We suppose that if any queue allocates all its memory then all elements will be discarded until the appearance of the free memory (i.e. until the exclusion from queue). Overflow is a typical not an emergency situation. Such behaviour is called the “ reset tail “ . We also suppose that the time is discrete and in the case of exclusion from an empty data structure there is no shutdown. We will adhere to the following notation: • m – size of memory, • n – number of queues in the memory, • p j – probability of insertion of an element into the j -th queue, • q j – probability of deletion of an element from the j -th queue, • r – probabilitiy of operation which doesn’t change the data structure length (for example only reading), • k j – size of memory separated to the queue with number j with sequential presentation, • l – the ratio of the size of node to the size of a pointer (for the linked presentation), • P ∗ – the part of time which the system is situated in the state of “ reset tail “ . We assume and the probabilities p j , q j , r are known. The problem is to find the part of time which the system is situated in the state of “ reset tail “ and find the optimal partition of memory in case of consecutive presentation.

  4. One queue Consider one FIFO-queue in the memory of size m and build a homogeneous Markov’s chain with m + 2 states, where states with numbers 0 . . . m corespond to the number fo elements in queue and the state with number m + 1 coresponds the state of “ reset tail “ . Build a matrix of transition probabilities P :   q + r p 0 0 . . . 0 0 0 0 0 q r p 0 . . . 0 0 0 0 0     0 q r p . . . 0 0 0 0 0     . . . . . . . . . . . . . . . . . . . . . . . . . . . .     0 0 0 0 . . . q r p 0 0     0 0 0 0 . . . 0 q r p 0      0 0 0 0 . . . 0 0 q r p    0 0 0 0 . . . 0 0 q r p The component α m +1 of the limit vector is needed to be find from the equations ( αP = α, α 0 + ... + α m +1 = 1) . The part of time which system is situated in the state of “ reset tail “ is equal to:  q − p q � = p   � q � m +1   − 1 α m +1 = (1) p p  q = p    m + 1

  5. Consecutive allocation of the queues Consider k 1 , . . . , k n is the fixed partition of the memory. As the mathematical model we consider the random walk on an integer lattice space inside n -dimensional parallelepiped with vertex at the origin, edges parallel to the axes and the lengths of edges k 1 , . . . , k n . ( i 1 , . . . , i n ) is the state of the system. 0 ≤ i 1 ≤ k 1 + 1 , . . . , 0 ≤ i n ≤ k n + 1 . i j = k j + 1 – the states of “ reset tail “ . α i 1 ...i n it the limit probability which system is situated in the state ( i 1 , . . . , i n ) . The problem is to find the part of time from the equations ( αP = α, || α || 1 = 1) . Figure 3: n = 2 , m = 17 , k 1 = 10 , k 2 = 7

  6. Consecutive allocation of the queues I 1 = { j : i j = 0 } I 2 = { j : 1 ≤ i j ≤ k j − 2 } I 3 = { j : i j = k j − 1 } I 4 = { j : i j = k j } I 5 = { j : i j = k j + 1 } The solve of the equation is:   � i 1 � i n � p 1 � p n �  1 − I 5 = ∅ α i 1 ...i n = C . . . p j  q 1 q n j ∈ I 4 � i 1 � i j − 1 � i n � p 1 � p j � p n I 5 = { j } α i 1 ...i j ...i n = C . . . . . . p j q 1 q j q n The constant C can be found from the normalization equation. The part of time which the system is situated in the state of “ reset tail “ is equal to: n s n q i − p i p i P ∗ = � � � p ∗ i = + � k i +1 k i + 1 � q i i =1 i =1 i = s +1 − 1 p i

  7. The optimal partition of memory 1. The case of equal probabilities p i = q i . The problem is to find n p i � min k i + 1 k 1 + ··· + k n = m i =1 Consider the function n − 1 p i p n � F ( k 1 , k 2 , . . . , k n − 1 ) = k i + 1 + n − 1 m − � i =1 k i + 1 i =1 and find its minimum considering conditions k i > 0 , k 1 + ... + k n − 1 < m : i = ( m + n ) √ p i k ∗ − 1 1 ≤ i ≤ n − 1 n √ p l � l =1 The minimum part of time which the system is situated in the state of “ reset tail “ is equal to: � n √ p i � 2 � n n n √ p i √ p i p i 1 � � � � � i =1 i + 1 = = k ∗ m + n m + n i =1 i =1 l =1

  8. The optimal partition of memory 2. The general case. Denote Z m – part of time which system is situated it the state of “ reset tail “ in the case of optimal partition of memory of size m . n � p ∗ Z m ( k 1 , . . . , k n ) = min i ( k i ) k 1 + ··· + k n = m i =1 p ∗ i is the part of time which i -th queue is situated in the state of “ reset tail “ . Consider the recurrence relation 1 ≤ i ≤ n ( p ∗ i ( k i ) − p ∗ Z m ( k 1 , . . . , k n ) = Z m − 1 − max i ( k i + 1)) The start value Z 0 is equal to n � Z 0 (0 , . . . , 0) = p i i =1 I.e. in the case of lack of memory, any attempt of insertion will lead to the lost of element. Using this scheme it is possible to calculate the optimal partition of memory and part of time which system is situated in the state of “ reset tail “ over the time O ( mn )

  9. The linked list implementation As the mathematical model we consider the random walk on the integer lattice in n -dimensional pyramid with edges 0 ≤ i 1 ≤ M, 0 ≤ i 2 ≤ M, . . . , 0 ≤ i n ≤ M and base i 1 + i 2 + · · · + i n = M . ( M = m (1 − 1 l )) ( i 1 , . . . , i n ) is the state of the system. The problem is to find the part of time from the equations ( αP = α, || α || 1 = 1) . Figure 4: n = 2 , M = 7

  10. The linked list implementation The solve of the equation is: � i 1 � i n � p 1 � p n α i 1 i 2 ...i n = C . . . 0 ≤ i 1 + · · · + i n ≤ M − 1 q 1 q n � i 1 � i n � p 1 � p n α i 1 i 2 ...i n = C (1 − p 1 − · · · − p n ) i 1 + · · · + i n = M . . . q 1 q n � i 1 � i n � p 1 � p n α i 1 i 2 ...i n = C ( p 1 + · · · + p n ) . . . i 1 + · · · + i n = M q 1 q n The constant C can be found from the normalization equation. 1. The case of different probabilities: p i /q i � = p j /q j and p i � = q i Denote x i = p i /q i , then the part of time which system is situated in the state of “ reset tail “ is equal to: x M + n − 1 n i � n i =1 � ( x i − x j ) j =1 P ∗ = ( p 1 + · · · + p n ) j � = i x M + n n 1 i � + n n i =1 ( x i − 1) � ( x i − x j ) � (1 − x j ) j =1 j =1 j � = i

  11. The linked list implementation 2. The general case: There is k 0 queues where p i = q i . There is k 1 queues where p i 1 /q i 1 = x 1 . ... There is k s queues where p i s /q i s = x s . The part of time which the system is situated in the state of “ reset tail “ is equal to: � � ∂ n − s − 1 x M + n − 1 s i � s ∂ k 0 − 1 x 0 ∂ k 1 − 1 x 1 . . . ∂ k s − 1 x s i =0 � ( x i − x j ) j =0 P ∗ = k 0 ( p 0 k 0 + · · · + p s k s ) j � = i � � x M + n ∂ n − s s i � s ∂ k 0 x 0 ∂ k 1 − 1 x 1 . . . ∂ k s − 1 x s i =0 � ( x i − x j ) j =0 j � = i

  12. Comparison between consecutive and linked presentations 1. p 1 > q 1 and p 1 > p i for i = 2 , . . . , n. q 1 q i Consecutive implementation: n P ∗ → � max( p i − q i , 0) i =1 Linked list implementation: � p 1 − q 1 � � � 1 − q 1 P ∗ l → ( p 1 + · · · + p n ) = ( p 1 + · · · + p n ) p 1 p 1 P ∗ c < P ∗ l even when the size of memory is rather small 2. p i = q i for i = 1 , . . . , n. n P ∗ c ≤ m + n n P ∗ l = M + n P ∗ c < P ∗ l 3. p i < q i for i = 1 , . . . , n. and p 1 > p i q 1 q i � � �� 1 m P ∗ � = O c ≈ exp − n 1 � m − n � − log n exp log( q i p i ) n 1 i =1 � log( q i p i ) i =1 � M � �� q 1 − m (1 − 1 l ) log q 1 � � �� P ∗ l = O = O exp p 1 p 1

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend