Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13943 for branches


Ignore:
Timestamp:
06/28/16 17:03:36 (8 years ago)
Author:
thasling
Message:

#2615:
implemented lock for timers, because if elapsed-method takes longer than the timer to elapse again, the method is called by another thread conccurently

Location:
branches/thasling/DistributedGA
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/thasling/DistributedGA/DistributedGA.ContactServer/ContactServiceImpl.cs

    r13924 r13943  
    1818
    1919    private Object logLock = new Object();
     20
     21    private Object timerLock = new Object();//if elapsed takes too long, another thread also enters the method
    2022
    2123    public ContactServiceImpl() {
     
    7880
    7981    private void CleanUpContactTable(object sender, ElapsedEventArgs e) {
    80       DateTime deadline = DateTime.Now;
    81       //collect items to remove
    82       List<PeerInfo> itemsToDelete = new List<PeerInfo>();
    83       foreach (PeerInfo pi in allPeers.Keys) {
    84         DateTime tmp;
    85         if (allPeers.TryGetValue(pi, out tmp)) {
    86           //if (tmp.AddHours(1f) < deadline)
    87           if (tmp.AddMinutes(1) < deadline)  //TODO
     82      lock (timerLock) {
     83        DateTime deadline = DateTime.Now;
     84        //collect items to remove
     85        List<PeerInfo> itemsToDelete = new List<PeerInfo>();
     86        foreach (PeerInfo pi in allPeers.Keys) {
     87          DateTime tmp;
     88          if (allPeers.TryGetValue(pi, out tmp)) {
     89            //if (tmp.AddHours(1f) < deadline)
     90            if (tmp.AddMinutes(1) < deadline)  //TODO
    8891                    {
    89             //if (tmp < deadline.AddHours(1f)) {
    90             itemsToDelete.Add(pi);
     92              //if (tmp < deadline.AddHours(1f)) {
     93              itemsToDelete.Add(pi);
     94            }
    9195          }
    9296        }
    93       }
    94       //remove items
    95       foreach (PeerInfo pi in itemsToDelete) {
    96         DateTime tmp;
    97         allPeers.TryRemove(pi, out tmp);
    98         Console.WriteLine(string.Format("Removed peer {0}:{1} from dictionary because last access was: {2}", pi.IpAddress, pi.Port, tmp));
     97        //remove items
     98        foreach (PeerInfo pi in itemsToDelete) {
     99          DateTime tmp;
     100          allPeers.TryRemove(pi, out tmp);
     101          Console.WriteLine(string.Format("Removed peer {0}:{1} from dictionary because last access was: {2}", pi.IpAddress, pi.Port, tmp));
     102        }
    99103      }
    100104    }
  • branches/thasling/DistributedGA/DistributedGA.ContactServer/DistributedGA.ContactServer.csproj

    r13524 r13943  
    5555  </ItemGroup>
    5656  <ItemGroup>
    57     <None Include="App.config" />
     57    <None Include="App.config">
     58      <SubType>Designer</SubType>
     59    </None>
    5860  </ItemGroup>
    5961  <ItemGroup>
  • branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfMessageSender.cs

    r13937 r13943  
    1818    private Timer timer; //sends cached messages to network in background
    1919
     20    private Object timerLock = new Object();
     21
    2022    public void Init(PeerInfo source) {
    2123      myself = source;
    2224      bufferedMessages = new SizedConcurrentQueue<KeyValuePair<PeerInfo, byte[][]>>();
    23       bufferedMessages.Limit = 1000;
     25      bufferedMessages.Limit = 100000;
    2426      timer = new Timer(1000 * 60); //each 5 minutes
    2527      timer.Elapsed += GenerateSendingTasks;
     
    5254    /// <param name="data">data to send</param>
    5355    private void SendDataFromQueue(PeerInfo destination, byte[][] data) {
    54       try {
    55         Console.WriteLine(string.Format("Sending data to {0}:{1} in the background...", destination.IpAddress, destination.Port));
    56         var serviceUrl = "DistributedGA.svc";
    57         var baseUri = new Uri(string.Concat("net.tcp://", destination.IpAddress, ":", destination.Port, "/DistributedGA"));
    58         var serviceUri = new Uri(baseUri, serviceUrl);
     56      lock (timerLock) {
     57        try {
     58          Console.WriteLine(string.Format("Sending data to {0}:{1} in the background...", destination.IpAddress, destination.Port));
     59          var serviceUrl = "DistributedGA.svc";
     60          var baseUri = new Uri(string.Concat("net.tcp://", destination.IpAddress, ":", destination.Port, "/DistributedGA"));
     61          var serviceUri = new Uri(baseUri, serviceUrl);
    5962
    60         var binding = new NetTcpBinding();
    61         var endpoint = new EndpointAddress(serviceUri);
    62         using (var myChannelFactory = new ChannelFactory<IMessageContract>(binding, endpoint)) {
    63           using (IClientChannel client = (IClientChannel)myChannelFactory.CreateChannel()) {
    64             ((IMessageContract)client).SendData(myself, data); //maybe timout exception...
     63          var binding = new NetTcpBinding();
     64          var endpoint = new EndpointAddress(serviceUri);
     65          using (var myChannelFactory = new ChannelFactory<IMessageContract>(binding, endpoint)) {
     66            using (IClientChannel client = (IClientChannel)myChannelFactory.CreateChannel()) {
     67              ((IMessageContract)client).SendData(myself, data); //maybe timout exception...
     68            }
    6569          }
    6670        }
     71        catch { } //if maybe sending failed (because of connection lost, etc.): just ignore
    6772      }
    68       catch { } //if maybe sending failed (because of connection lost, etc.): just ignore
    6973    }
    7074  }
  • branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfPeerListManager.cs

    r13937 r13943  
    1515
    1616    private Timer timer = null; //sends heartbeat to contact-server
     17
     18    private Object timerLock = new Object();
    1719
    1820    private ChannelFactory<IContactService> myChannelFactory;
     
    7375        res.Add(allPeers.ElementAt(index));
    7476      }
    75       return res;
     77      return allPeers;
    7678    }
    7779
     
    9092
    9193    private void SendHeartbeatToServer(object sender, ElapsedEventArgs e) {
    92       try {
    93         heartbeatClient.UpdateHeartbeat(myself);
     94      lock (timerLock) {
     95        try {
     96          heartbeatClient.UpdateHeartbeat(myself);
     97        }
     98        catch { } //nothing to do
    9499      }
    95       catch { } //nothing to do
    96100    }
    97101
  • branches/thasling/DistributedGA/DistributedGA.Hive/P2PMigrationAnalyzer.cs

    r13905 r13943  
    9797      // init P2P
    9898      h = new PeerNetworkMessageHandler();
    99       var peer = h.GetPeerInfo();
    100       peer.ProblemInstance = ((StringValue)Parameters["JobGUID"].ActualValue).Value;
    10199      var lanIpPrefix = ((StringValue)(Parameters["LanIpPrefix"].ActualValue)).Value;
    102100      var contactServerUri = ((StringValue)(Parameters["ContactServerURL"].ActualValue)).Value;
    103101      h.Init(lanIpPrefix, contactServerUri);
     102      var peer = h.GetPeerInfo();
     103      peer.ProblemInstance = ((StringValue)Parameters["JobGUID"].ActualValue).Value;
    104104    }
    105105
Note: See TracChangeset for help on using the changeset viewer.