Changeset 1348


Ignore:
Timestamp:
Apr 24, 2010, 5:20:27 PM (12 years ago)
Author:
arnold
Message:

P2PManager/Worker: Manager sends a "no more jobs left" message to the requesting worker or after receiving the last job result to all active registered workers. After receiving this message, the workers stop their "waiting for new jobs" timer, which sends "free worker" messages to the Manager periodically.
For future use: After worker has received the "no more jobs left" message from the Manager, it should register with a new Manager to computate more jobs.

Location:
trunk/CrypPlugins
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/PeerToPeerJobs/JobMessages.cs

    r1155 r1348  
    4444        /// messages FROM the Manager TO the P2PJobAdmin)
    4545        /// </summary>
    46         JobPart = 203
     46        JobPart = 203,
     47        /// <summary>
     48        /// Manager should send this msgType to all requesting
     49        /// workers, when it has no more jobs left
     50        /// </summary>
     51        NoMoreJobsLeft = 204
    4752    }
    4853
     
    267272                    retValue = false;
    268273                else
     274                    retValue = true;
     275            }
     276            return retValue;
     277        }
     278
     279        // TODO: Create NoMoreJobsLeft Msg
     280
     281        /// <summary>
     282        /// When the Manager has no more jobs left, it should send a "no more
     283        /// jobs left" message to all job-requesting Workers.
     284        /// </summary>
     285        /// <returns>serialized "no more jobs left" message</returns>
     286        public static byte[] CreateNoMoreJobsLeftMessage()
     287        {
     288            byte[] retValue = new byte[2];
     289            retValue[0] = (byte)MessageJobType.NoMoreJobsLeft;
     290            retValue[1] = 1;
     291            return retValue;
     292        }
     293
     294        /// <summary>
     295        /// Only workers can receive this message type. Manager sent
     296        /// this Msg, when it has no more jobs left to allocate.
     297        /// </summary>
     298        /// <param name="msg"></param>
     299        /// <returns></returns>
     300        public static bool GetNoMoreJobsLeftMessage(byte[] msg)
     301        {
     302            bool retValue = false;
     303            if ((MessageJobType)msg[0] == MessageJobType.NoMoreJobsLeft && msg.Length == 2)
     304            {
     305                if (msg[1] == 1)
    269306                    retValue = true;
    270307            }
  • trunk/CrypPlugins/PeerToPeerManager_NEW/P2PManagerBase_NEW.cs

    r1264 r1348  
    2727 *   isn't implemented yet ((de)serialization of the subscribers is
    2828 *   implemented and tested)
    29  * - Manager-change is possible, but catch job history isn't implemented yes
     29 * - Manager-change is possible, but catch job history isn't implemented yet
    3030 *   ((de)serialization of job management lists)
    3131 * - Benchmarking the working peers
     
    167167             * Manager can replace it and then allocate Jobs to the free workers*/
    168168            GuiLogging("All Job results received, so deregistering from the solution network to accomodate this topic for another Manager.",NotificationLevel.Info);
     169
     170            // added by Arnie 2010.04.24
     171            SendNoMoreJobsLeftMsgToAllWorkers();
     172
    169173            Stop(PubSubMessageType.Unregister);
     174        }
     175
     176        // added by Arnie 2010.04.24
     177        private void SendNoMoreJobsLeftMsgToAllWorkers()
     178        {
     179            int i = 0;
     180            byte[] noMoreJobsLeftMsg = JobMessages.CreateNoMoreJobsLeftMessage();
     181            foreach (PeerId wkr in base.peerManagement.GetAllSubscribers())
     182            {
     183                this.p2pControl.SendToPeer(noMoreJobsLeftMsg, wkr);
     184                i++;
     185            }
     186            GuiLogging("Sended 'No more jobs left' messages to " + i + " workers.", NotificationLevel.Debug);
    170187        }
    171188
     
    467484                else
    468485                {
    469                     //todo: insert sending "no more jobs left msg" to the free worker, so it can stop its Free-Msg-Timer
     486                    //edited by Arnie 2010.04.24
     487                    //sending "no more jobs left msg" to the free worker, so it can stop its Free-Msg-Timer
     488                    base.p2pControl.SendToPeer(JobMessages.CreateNoMoreJobsLeftMessage(), worker);
     489
    470490                    GuiLogging("No more jobs left. So wait for the last results, than close this task.", NotificationLevel.Debug);
    471491                    if (OnNoMoreJobsLeft != null)
  • trunk/CrypPlugins/PeerToPeerWorker_NEW/P2PJobAdminBase.cs

    r1264 r1348  
    7676            private set { this.isWorking = value; }
    7777        }
     78
     79        private bool actualMngrHasNoMoreJobsLeft = false;
     80        public bool ActualMngrHasNoMoreJobsLeft
     81        {
     82            get { return this.actualMngrHasNoMoreJobsLeft; }
     83            private set{ this.actualMngrHasNoMoreJobsLeft = value;}
     84        }
     85
    7886        ///// <summary>
    7987        ///// everytime, when start processing a new job, set
     
    184192                StartProcessing(senderId, serializedRawJobPartData);
    185193            }
    186             else
    187             {
    188                 GuiLogging("Received some strange data (no JobPart) from peer '" + senderId.ToString()
     194            else if (JobMessages.GetMessageJobType(data[0]) == MessageJobType.NoMoreJobsLeft)
     195            {
     196                this.ActualMngrHasNoMoreJobsLeft = true;
     197                this.timerWaitingForJobs.Stop();
     198                GuiLogging("Received 'no more jobs left' message from the Manager. Stopped waiting for jobs timer.", NotificationLevel.Debug);
     199                // TODO: for future use maybe register to another task, because this task has no more
     200                //       jobs to computate --> after registering with a new Manager, set this.ActualMngrHasNoMoreJobsLeft to true!!!
     201            }
     202            else
     203            {
     204                GuiLogging("Received some strange data (no JobPart) from peer '" + senderId.ToString()
    189205                    + "'. Data: " + Encoding.UTF8.GetString(data), NotificationLevel.Debug);
    190206            }
     
    263279            else
    264280            {
    265                 // no more jobs in the waiting stack, so send Mngr the information, that Worker is waiting for new jobs now
    266                 this.p2pControl.SendToPeer(JobMessages.CreateFreeWorkerStatusMessage(true), base.ActualPublisher);
    267                 GuiLogging("No jobs in the 'waitingJob'-Stack, so send 'free'-information to the Manager. Mngr-Id: '" + base.ActualPublisher.ToString() + "'.", NotificationLevel.Info);
    268                 // If this timer elapses, it will check if the isWorking flag is true. Than it will stop the timer.
    269                 // Otherwise it will send a new free msg to the Manager, if the last free msg got lost
    270                 this.timerWaitingForJobs.Start();
     281                if (!this.ActualMngrHasNoMoreJobsLeft)
     282                {
     283                    // no more jobs in the waiting stack, so send Mngr the information, that Worker is waiting for new jobs now
     284                    this.p2pControl.SendToPeer(JobMessages.CreateFreeWorkerStatusMessage(true), base.ActualPublisher);
     285                    GuiLogging("No jobs in the 'waitingJob'-Stack, so send 'free'-information to the Manager. Mngr-Id: '" + base.ActualPublisher.ToString() + "'.", NotificationLevel.Info);
     286                    // If this timer elapses, it will check if the isWorking flag is true. Than it will stop the timer.
     287                    // Otherwise it will send a new free msg to the Manager, if the last free msg got lost
     288                    this.timerWaitingForJobs.Start();
     289                }
     290                else
     291                {
     292                    GuiLogging("Worker has noticed that Manager has no more jobs left.", NotificationLevel.Debug);
     293                    // TODO: for future use maybe register to another task, because this task has no more
     294                    //       jobs to computate --> after registering with a new Manager, set this.ActualMngrHasNoMoreJobsLeft to true!!!
     295                }
    271296            }
    272297        }
Note: See TracChangeset for help on using the changeset viewer.