From bdc13455011c9de2877813138a49d83fc52d3142 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 2 Oct 2009 13:08:15 -0700 Subject: * Removed even more unnecessary state variables from J2KImage * Fixed the incorrect "out of memory?" exception messages and replaced them with useful information * Cleaned up J2KImage and LLImageManager to conform to coding conventions --- .../Region/ClientStack/LindenUDP/LLImageManager.cs | 46 +++++++++++----------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs b/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs index a484fdf..d641b6c 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs @@ -45,7 +45,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP { public int Compare(J2KImage x, J2KImage y) { - return x.m_requestedPriority.CompareTo(y.m_requestedPriority); + return x.Priority.CompareTo(y.Priority); } } @@ -94,7 +94,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP // Do a linear search for this texture download lock (m_priorityQueue) - m_priorityQueue.Find(delegate(J2KImage img) { return img.m_requestedUUID == newRequest.RequestedAssetID; }, out imgrequest); + m_priorityQueue.Find(delegate(J2KImage img) { return img.TextureID == newRequest.RequestedAssetID; }, out imgrequest); if (imgrequest != null) { @@ -105,7 +105,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP try { lock (m_priorityQueue) - m_priorityQueue.Delete(imgrequest.m_priorityQueueHandle); + m_priorityQueue.Delete(imgrequest.PriorityQueueHandle); } catch (Exception) { } } @@ -116,29 +116,29 @@ namespace OpenSim.Region.ClientStack.LindenUDP //Check the packet sequence to make sure this isn't older than //one we've already received - if (newRequest.requestSequence > imgrequest.m_lastSequence) + if (newRequest.requestSequence > imgrequest.LastSequence) { //Update the sequence number of the last RequestImage packet - imgrequest.m_lastSequence = newRequest.requestSequence; + imgrequest.LastSequence = newRequest.requestSequence; //Update the requested discard level - imgrequest.m_requestedDiscardLevel = newRequest.DiscardLevel; + imgrequest.DiscardLevel = newRequest.DiscardLevel; //Update the requested packet number - imgrequest.m_requestedPacketNumber = newRequest.PacketNumber; + imgrequest.StartPacket = newRequest.PacketNumber; //Update the requested priority - imgrequest.m_requestedPriority = newRequest.Priority; + imgrequest.Priority = newRequest.Priority; try { lock (m_priorityQueue) - m_priorityQueue.Replace(imgrequest.m_priorityQueueHandle, imgrequest); + m_priorityQueue.Replace(imgrequest.PriorityQueueHandle, imgrequest); } catch (Exception) { - imgrequest.m_priorityQueueHandle = null; + imgrequest.PriorityQueueHandle = null; lock (m_priorityQueue) - m_priorityQueue.Add(ref imgrequest.m_priorityQueueHandle, imgrequest); + m_priorityQueue.Add(ref imgrequest.PriorityQueueHandle, imgrequest); } //Run an update @@ -161,29 +161,29 @@ namespace OpenSim.Region.ClientStack.LindenUDP imgrequest = new J2KImage(this); //Assign our decoder module - imgrequest.m_j2kDecodeModule = m_j2kDecodeModule; + imgrequest.J2KDecoder = m_j2kDecodeModule; //Assign our asset cache module - imgrequest.m_assetCache = m_assetCache; + imgrequest.AssetService = m_assetCache; //Assign the requested discard level - imgrequest.m_requestedDiscardLevel = newRequest.DiscardLevel; + imgrequest.DiscardLevel = newRequest.DiscardLevel; //Assign the requested packet number - imgrequest.m_requestedPacketNumber = newRequest.PacketNumber; + imgrequest.StartPacket = newRequest.PacketNumber; //Assign the requested priority - imgrequest.m_requestedPriority = newRequest.Priority; + imgrequest.Priority = newRequest.Priority; //Assign the asset uuid - imgrequest.m_requestedUUID = newRequest.RequestedAssetID; + imgrequest.TextureID = newRequest.RequestedAssetID; //Assign the requested priority - imgrequest.m_requestedPriority = newRequest.Priority; + imgrequest.Priority = newRequest.Priority; //Add this download to the priority queue lock (m_priorityQueue) - m_priorityQueue.Add(ref imgrequest.m_priorityQueueHandle, imgrequest); + m_priorityQueue.Add(ref imgrequest.PriorityQueueHandle, imgrequest); //Run an update imgrequest.RunUpdate(); @@ -249,12 +249,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP lock (m_priorityQueue) imagereq = m_priorityQueue.FindMax(); - if (imagereq.m_decoded == true) + if (imagereq.IsDecoded == true) { // we need to test this here now that we are dropping assets - if (!imagereq.m_hasasset) + if (!imagereq.HasAsset) { - m_log.WarnFormat("[LLIMAGE MANAGER]: Re-requesting the image asset {0}", imagereq.m_requestedUUID); + m_log.WarnFormat("[LLIMAGE MANAGER]: Re-requesting the image asset {0}", imagereq.TextureID); imagereq.RunUpdate(); continue; } @@ -268,7 +268,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP try { lock (m_priorityQueue) - m_priorityQueue.Delete(imagereq.m_priorityQueueHandle); + m_priorityQueue.Delete(imagereq.PriorityQueueHandle); } catch (Exception) { } } -- cgit v1.1 From 332d3eb1bb4aecf67d56e64686db3e3851b848ea Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 2 Oct 2009 16:53:35 -0700 Subject: * Removed code that is no longer used with Melanie's queue callback optimization * Moved all priority queue access to helper functions to improve reliability and readability * New version of CSJ2K.dll (from libomv source tree) that fixes a JPEG2000 comment decoding bug --- .../Region/ClientStack/LindenUDP/LLImageManager.cs | 214 +++++++++------------ 1 file changed, 88 insertions(+), 126 deletions(-) (limited to 'OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs b/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs index d641b6c..facfb9d 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs @@ -50,43 +50,38 @@ namespace OpenSim.Region.ClientStack.LindenUDP } private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private bool m_shuttingdown = false; - private long m_lastloopprocessed = 0; - private AssetBase m_missingImage = null; - + private bool m_shuttingdown; + private long m_lastloopprocessed; + private AssetBase m_missingImage; private LLClientView m_client; //Client we're assigned to private IAssetService m_assetCache; //Asset Cache private IJ2KDecoder m_j2kDecodeModule; //Our J2K module private C5.IntervalHeap m_priorityQueue = new C5.IntervalHeap(10, new J2KImageComparer()); + private object m_syncRoot = new object(); + + public LLClientView Client { get { return m_client; } } + public AssetBase MissingImage { get { return m_missingImage; } } public LLImageManager(LLClientView client, IAssetService pAssetCache, IJ2KDecoder pJ2kDecodeModule) { m_client = client; m_assetCache = pAssetCache; + if (pAssetCache != null) m_missingImage = pAssetCache.Get("5748decc-f629-461c-9a36-a35a221fe21f"); - else - m_log.Error("[ClientView] - couldn't set missing image asset, falling back to missing image packet. This is known to crash the client"); + + if (m_missingImage == null) + m_log.Error("[ClientView] - Couldn't set missing image asset, falling back to missing image packet. This is known to crash the client"); m_j2kDecodeModule = pJ2kDecodeModule; } - public LLClientView Client - { - get { return m_client; } - } - - public AssetBase MissingImage - { - get { return m_missingImage; } - } - + /// + /// Handles an incoming texture request or update to an existing texture request + /// + /// public void EnqueueReq(TextureRequestArgs newRequest) { - //newRequest is the properties of our new texture fetch request. - //Basically, here is where we queue up "new" requests.. - // .. or modify existing requests to suit. - //Make sure we're not shutting down.. if (!m_shuttingdown) { @@ -125,21 +120,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP imgrequest.DiscardLevel = newRequest.DiscardLevel; //Update the requested packet number - imgrequest.StartPacket = newRequest.PacketNumber; + imgrequest.StartPacket = Math.Max(1, newRequest.PacketNumber); //Update the requested priority imgrequest.Priority = newRequest.Priority; - try - { - lock (m_priorityQueue) - m_priorityQueue.Replace(imgrequest.PriorityQueueHandle, imgrequest); - } - catch (Exception) - { - imgrequest.PriorityQueueHandle = null; - lock (m_priorityQueue) - m_priorityQueue.Add(ref imgrequest.PriorityQueueHandle, imgrequest); - } + UpdateImageInQueue(imgrequest); //Run an update imgrequest.RunUpdate(); @@ -159,31 +144,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP // newRequest.RequestedAssetID, newRequest.DiscardLevel, newRequest.PacketNumber, newRequest.Priority); imgrequest = new J2KImage(this); - - //Assign our decoder module imgrequest.J2KDecoder = m_j2kDecodeModule; - - //Assign our asset cache module imgrequest.AssetService = m_assetCache; - - //Assign the requested discard level imgrequest.DiscardLevel = newRequest.DiscardLevel; - - //Assign the requested packet number - imgrequest.StartPacket = newRequest.PacketNumber; - - //Assign the requested priority + imgrequest.StartPacket = Math.Max(1, newRequest.PacketNumber); imgrequest.Priority = newRequest.Priority; - - //Assign the asset uuid imgrequest.TextureID = newRequest.RequestedAssetID; - - //Assign the requested priority imgrequest.Priority = newRequest.Priority; //Add this download to the priority queue - lock (m_priorityQueue) - m_priorityQueue.Add(ref imgrequest.PriorityQueueHandle, imgrequest); + AddImageToQueue(imgrequest); //Run an update imgrequest.RunUpdate(); @@ -194,105 +164,97 @@ namespace OpenSim.Region.ClientStack.LindenUDP public bool ProcessImageQueue(int count, int maxpack) { - lock (this) + J2KImage imagereq; + int numCollected = 0; + + lock (m_syncRoot) { - //count is the number of textures we want to process in one go. - //As part of this class re-write, that number will probably rise - //since we're processing in a more efficient manner. + m_lastloopprocessed = DateTime.Now.Ticks; - // this can happen during Close() - if (m_client == null) + // This can happen during Close() + if (m_client == null || m_client.PacketHandler == null || m_client.PacketHandler.PacketQueue == null) return false; - - int numCollected = 0; - - //Calculate our threshold - int threshold; - if (m_lastloopprocessed == 0) - { - if (m_client.PacketHandler == null || m_client.PacketHandler.PacketQueue == null || m_client.PacketHandler.PacketQueue.TextureThrottle == null) - return false; - //This is decent for a semi fast machine, but we'll calculate it more accurately based on time below - threshold = m_client.PacketHandler.PacketQueue.TextureThrottle.Current / 6300; - m_lastloopprocessed = DateTime.Now.Ticks; - } - else + + while ((imagereq = GetHighestPriorityImage()) != null) { - double throttleseconds = ((double)DateTime.Now.Ticks - (double)m_lastloopprocessed) / (double)TimeSpan.TicksPerSecond; - throttleseconds = throttleseconds * m_client.PacketHandler.PacketQueue.TextureThrottle.Current; - - //Average of 1000 bytes per packet - throttleseconds = throttleseconds / 1000; - - //Safe-zone multiplier of 2.0 - threshold = (int)(throttleseconds * 2.0); - m_lastloopprocessed = DateTime.Now.Ticks; - - } - - if (m_client.PacketHandler == null) - return false; - - if (m_client.PacketHandler.PacketQueue == null) - return false; - - if (threshold < 10) - threshold = 10; - - //Uncomment this to see what the texture stack is doing - //m_log.Debug("Queue: " + m_client.PacketHandler.PacketQueue.getQueueCount(ThrottleOutPacketType.Texture).ToString() + " Threshold: " + threshold.ToString() + " outstanding: " + m_outstandingtextures.ToString()); - if (true) //m_client.PacketHandler.PacketQueue.GetQueueCount(ThrottleOutPacketType.Texture) < threshold) - { - while (m_priorityQueue.Count > 0) + if (imagereq.IsDecoded == true) { - J2KImage imagereq = null; - lock (m_priorityQueue) - imagereq = m_priorityQueue.FindMax(); + ++numCollected; - if (imagereq.IsDecoded == true) + if (imagereq.SendPackets(m_client, maxpack)) { - // we need to test this here now that we are dropping assets - if (!imagereq.HasAsset) - { - m_log.WarnFormat("[LLIMAGE MANAGER]: Re-requesting the image asset {0}", imagereq.TextureID); - imagereq.RunUpdate(); - continue; - } - - ++numCollected; - - //SendPackets will send up to ten packets per cycle - if (imagereq.SendPackets(m_client, maxpack)) - { - // Send complete. Destroy any knowledge of this transfer - try - { - lock (m_priorityQueue) - m_priorityQueue.Delete(imagereq.PriorityQueueHandle); - } - catch (Exception) { } - } + // Send complete. Destroy any knowledge of this transfer + RemoveImageFromQueue(imagereq); } - - if (numCollected == count) - break; } - } - return m_priorityQueue.Count > 0; + if (numCollected == count) + break; + } } + + return m_priorityQueue.Count > 0; } //Faux destructor public void Close() { - m_shuttingdown = true; m_j2kDecodeModule = null; m_assetCache = null; m_client = null; } + #region Priority Queue Helpers + + J2KImage GetHighestPriorityImage() + { + J2KImage image = null; + + if (m_priorityQueue.Count > 0) + { + try + { + lock (m_priorityQueue) + image = m_priorityQueue.FindMax(); + } + catch (Exception) { } + } + + return image; + } + + void AddImageToQueue(J2KImage image) + { + image.PriorityQueueHandle = null; + + lock (m_priorityQueue) + m_priorityQueue.Add(ref image.PriorityQueueHandle, image); + } + + void RemoveImageFromQueue(J2KImage image) + { + try + { + lock (m_priorityQueue) + m_priorityQueue.Delete(image.PriorityQueueHandle); + } + catch (Exception) { } + } + + void UpdateImageInQueue(J2KImage image) + { + lock (m_priorityQueue) + { + try { m_priorityQueue.Replace(image.PriorityQueueHandle, image); } + catch (Exception) + { + image.PriorityQueueHandle = null; + m_priorityQueue.Add(ref image.PriorityQueueHandle, image); + } + } + } + #endregion Priority Queue Helpers } } -- cgit v1.1 From 5b19d5a7b763a5ff5a7380f00c08fc30f4707588 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 4 Oct 2009 14:05:58 -0700 Subject: Reduced locking. --- OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs b/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs index facfb9d..2120d33 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLImageManager.cs @@ -167,8 +167,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP J2KImage imagereq; int numCollected = 0; - lock (m_syncRoot) - { + //lock (m_syncRoot) + //{ m_lastloopprocessed = DateTime.Now.Ticks; // This can happen during Close() @@ -191,7 +191,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP if (numCollected == count) break; } - } + //} return m_priorityQueue.Count > 0; } @@ -211,16 +211,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP { J2KImage image = null; - if (m_priorityQueue.Count > 0) + lock (m_priorityQueue) { - try + + if (m_priorityQueue.Count > 0) { - lock (m_priorityQueue) + try + { image = m_priorityQueue.FindMax(); + } + catch (Exception) { } } - catch (Exception) { } } - return image; } -- cgit v1.1