Click here to Skip to main content
15,887,596 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralPagerank and its mathematics: Explanation needed Pin
kentipsy20-Sep-09 8:24
kentipsy20-Sep-09 8:24 
GeneralRe: Pagerank and its mathematics: Explanation needed Pin
Richard MacCutchan20-Sep-09 9:41
mveRichard MacCutchan20-Sep-09 9:41 
QuestionHow to manage a share buf array? Pin
donniehan18-Sep-09 0:04
donniehan18-Sep-09 0:04 
AnswerRe: How to manage a share buf array? Pin
Luc Pattyn18-Sep-09 2:32
sitebuilderLuc Pattyn18-Sep-09 2:32 
GeneralRe: How to manage a share buf array? Pin
donniehan18-Sep-09 4:06
donniehan18-Sep-09 4:06 
GeneralRe: How to manage a share buf array? Pin
Luc Pattyn18-Sep-09 4:15
sitebuilderLuc Pattyn18-Sep-09 4:15 
GeneralRe: How to manage a share buf array? Pin
donniehan18-Sep-09 13:43
donniehan18-Sep-09 13:43 
GeneralRe: How to manage a share buf array? Pin
Luc Pattyn18-Sep-09 14:48
sitebuilderLuc Pattyn18-Sep-09 14:48 
Hi,

no I have no experience with Postgres SQL, but that won't matter much I think.


donniehan wrote:
It takes very short time for each msg to be handled by master.


That is very good. It will be key to your system working well.

My simple design would consist of:
- a single Message class that will be instantiated a number of times; the instances will be recycled without loading the garbage collector.
- an "emptyCollection" holding a number of empty message objects; think of it as a queue, although other kinds of collections could work too.
- an "emptyLock" object used to guard operations on emptyCollection;
- a "filledCollection" holding a number of filled message objects; again think of it as a queue.
- a "filledLock" object used to guard operations on filledCollection.
- emptyCollection+emptyLock and filledCollection+filledLock could be two instances of a single class MySafeCollection.

The initialization code would create a sufficient number of message instances and put them in the emptyCollection; the filledCollection is still empty.

Then the system really starts and performs these steps:
1. the producers obtain a message object quickly (getting one from emptyCollection, this must be protected by locking on emptyLock, which never will take long);
2. let the producer fill the message object;
3. let the producer put its filled message into the "filledCollection", using the filledLock, which again will not take long.
4. let the consumer obtain a filled message object from the filledCollection(again shortly using the filledLock).
5. let the consumer process the message; as this is a short operation and should never become a bottleneck I would consider doing this on a thread with slightly higher priority.
6. let the consumer return the message to the "emptyCollection" using the emptyLock.

Possible refinements:
A. You still need a signaling mechanism: each time a producer adds something to the filledCollection, it should send a signal to the single consumer, so it goes and fetches one (or more) messages from the filledCollection. This avoids the need for a polling loop in which the consumer would waste CPU cycles when no messages got filles.
B. A producer needing a message object and not finding one in the "emptyCollection" could create a new one; that would make the initialization unnecessary, however when things go terribly wrong, you may end up with a huge number of messages in the filledCollection.

I have implemented the above scheme numerous times inside embedded systems (i.e.using a proprietary operating system, not .NET or Windows). I know it works very well and is very performant.

Smile | :)

Luc Pattyn

Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.

Local announcement (Antwerp region): Lange Wapper? Neen!


GeneralRe: How to manage a share buf array? Pin
donniehan20-Sep-09 18:03
donniehan20-Sep-09 18:03 
GeneralRe: How to manage a share buf array? [modified] Pin
Luc Pattyn21-Sep-09 1:17
sitebuilderLuc Pattyn21-Sep-09 1:17 
GeneralRe: How to manage a share buf array? Pin
donniehan21-Sep-09 2:00
donniehan21-Sep-09 2:00 
GeneralRe: How to manage a share buf array? Pin
Luc Pattyn21-Sep-09 2:07
sitebuilderLuc Pattyn21-Sep-09 2:07 
QuestionHough Circular transform Pin
lcssiva16-Sep-09 1:38
lcssiva16-Sep-09 1:38 
AnswerRe: Hough Circular transform Pin
Alan Balkany16-Sep-09 3:27
Alan Balkany16-Sep-09 3:27 
GeneralRe: Hough Circular transform Pin
Luc Pattyn16-Sep-09 4:08
sitebuilderLuc Pattyn16-Sep-09 4:08 
GeneralRe: Hough Circular transform Pin
Alan Balkany16-Sep-09 4:24
Alan Balkany16-Sep-09 4:24 
GeneralRe: Hough Circular transform Pin
Luc Pattyn16-Sep-09 4:39
sitebuilderLuc Pattyn16-Sep-09 4:39 
GeneralRe: Hough Circular transform Pin
Fatbuddha 116-Sep-09 5:02
Fatbuddha 116-Sep-09 5:02 
GeneralRe: Hough Circular transform Pin
Alan Balkany16-Sep-09 5:17
Alan Balkany16-Sep-09 5:17 
GeneralRe: Hough Circular transform Pin
Luc Pattyn16-Sep-09 5:33
sitebuilderLuc Pattyn16-Sep-09 5:33 
GeneralRe: Hough Circular transform [modified] Pin
Member 419459316-Sep-09 5:12
Member 419459316-Sep-09 5:12 
GeneralRe: Hough Circular transform Pin
Luc Pattyn16-Sep-09 5:29
sitebuilderLuc Pattyn16-Sep-09 5:29 
GeneralRe: Hough Circular transform Pin
lcssiva16-Sep-09 4:34
lcssiva16-Sep-09 4:34 
QuestionImage circle counting Pin
lcssiva16-Sep-09 1:14
lcssiva16-Sep-09 1:14 
AnswerRe: Image circle counting Pin
Alan Balkany16-Sep-09 3:31
Alan Balkany16-Sep-09 3:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.