Select to view content in your preferred language

Odd Behavior - map service often doesn't load first attempt.

2991
12
07-22-2010 09:11 AM
MikeJun
Emerging Contributor
Many staff complain about map doesn't show up at first attempt even though the interface show up fine. However it will show up fine when they refresh the page or close IE and reopen the web page.

This odd behavior happens inconsistently and I wonder if they is any ways to trouble shoot this.

Thanks,

Mike.
Tags (2)
0 Kudos
12 Replies
JamesKo
Occasional Contributor
I seem to recall a thread in the old forum regarding sleeping map services:

http://forums.esri.com/Thread.asp?c=158&f=2421&t=264894&mc=26#msgid830021
0 Kudos
KeithPalmer
Emerging Contributor
That is l the problem I had recently too.  The sleeping map services were the problem.  I ended up having to refresh the services every 15 minutes to keep the map displaying properly.  To save you the trouble of finding the script in the other forums:

'declare web app variable, set variable to be an IE application
Dim webApp
Set webApp= CreateObject("InternetExplorer.Application")

'set visibility of the web app, can be set to false to run in the background
webApp.Visible = false

'declare a counter variable as integer, set it to zero
Dim counter
counter = 0

'declare array to hold names of different services
'simply increase the array by +1 and add a new entry for every new service that gets published
'remember that the services array is 0 based.
dim services(4)
services(0)="Ortho/MapServer"
services(1)="Basemap/MapServer"
services(2)="Parcels/MapServer"
services(x)="Other map services"/MapServer"

'the following loop uses the REST API and the array to step through each service page
'wait 5 seconds, then navigate to the next service. The loop runs 5 times.
Do while counter < 5
    For Each x in services     
      webApp.Navigate "http://<server name>/ArcGIS/rest/services/"& x
      wscript.sleep(5000)
    Next' 
  counter = counter + 1
Loop

webApp.quit
Set webApp = nothing

Save to a .vbs file and add as a Scheduled Task.  Make sure you refresh at least every hour if not more frequently.

-Keith
0 Kudos
MikeJun
Emerging Contributor
Hi Keith,

Thank you so much for the solution.

Below is my modified vesion of yours. The only thing I change is service name and rest service path name.

I downloaded vbs definition syntax in textpad and put this code in and save as sleepmapservicecure.vbs. Since I don't have much vbs experience, I don't know there is any error in the code or not. When I double click on this vbs file, it seems like nothing happen.

However I do notice that there is apostrophe right behine NEXT command in your code. I wonder if this is right.

Thanks so much.


+++++++++++++++++++++++++++++
Dim webApp
Set webApp= CreateObject("InternetExplorer.Application")

webApp.Visible = false

Dim counter
counter = 0

dim services(4)
services(0)="Crime_Layer/MapServer"
services(1)="Crime_Base/MapServer"
services(2)="Ortho2009/MapServer"

Do while counter < 5
For Each x in services
webApp.Navigate "http://cobgisweb/ArcGIS/rest/services/"& x
wscript.sleep(5000)
Next'
counter = counter + 1
Loop

webApp.quit
Set webApp = nothing
0 Kudos
MikeJun
Emerging Contributor
Please disregard above reply.

I totally understood how it work when I switch to webapp.Visible = True.

By the way, I took out apostrophe after NEXT.

THANK YOU SO MUCH.

I'll set a schedule task now and see if it cures the sleeping service.
0 Kudos
MatthewLawton
Deactivated User
I gave up on solving this ages ago! Thank you for posting a solution in a clear and concise manner. My users will no longer have to suffer.
0 Kudos
PaulLang
Deactivated User
Fails at line 30 after first pass, any clue?

Dim webApp
Set webApp= CreateObject("InternetExplorer.Application")

webApp.Visible = false

Dim counter
counter = 0

dim services(16)
services(0)="Daily/Annotation/MapServer"
services(1)="Daily/Dynamic/MapServer"
services(2)="Imagery/Orthos2009/MapServer"
services(3)="Imagery/Orthos2007/MapServer"
services(4)="Imagery/Orthos2005/MapServer"
services(5)="Imagery/Orthos2000/MapServer"
services(6)="Imagery/Orthos1997/MapServer"
services(7)="Monthly/Municipal/MapServer"
services(8)="Monthly/Physical/MapServer"
services(9)="Monthly/PublicSafety/MapServer"
services(10)="Monthly/TaxBase/MapServer"
services(11)="Static/Natural/MapServer"
services(12)="Static/ParcelSales/MapServer"
services(13)="Static/StartUp/MapServer"
services(14)="Static/Topography/MapServer"
services(15)="Static/Natural/MapServer"


Do while counter < 17
For Each x in services
webApp.Navigate "http://gcgis/ArcGIS/rest/services/"&x
wscript.sleep(5000)
Next
counter = counter + 1
Loop

webApp.quit

Set webApp = nothing
0 Kudos
MatthewLawton
Deactivated User
I noticed you don't have a space between "&x". Not sure if that would cause the problem. Also, if you are running it on your actual web server then you can just use "localhost" as below:

webApp.Navigate "http://localhost/ArcGIS/rest/services/"& x

But I am not sure if this is really doing what it is supposed to. I am running this as a Scheduled Task every 20 minutes and I am still getting sleepy services. I may change this script to directly access my actual web applications instead of the services pages in REST.
0 Kudos
PaulLang
Deactivated User
I tried it with and without spaces before posting.  Would not run on my server, but runs fine on my pc.
I agree no change is map service display; it�??s about 50/50 for me.
0 Kudos
MatthewLawton
Deactivated User
I think I have developed a better method to "wake up" the sleepy map services. Here is a generic HTM page I have created utilizing the JavaScript API that will automatically run through all the available MapServer services that exist on the server in REST. It loads them into a single map on the page. I am going to set the VBS script to point to this page and open it up every 20 minutes.

I understand that the "sleepy map service" issue is supposed to be solved in ArcGIS Server 10, but for those of us staying in 9.x a little longer, perhaps this will provide some relief.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
 <meta http-equiv="content-type" content="text/html; charset=utf-8">
 <title>ArcGIS REST Map Services Keep Alive</title>
 <link rel="stylesheet" href="https://community.esri.com/ArcGIS/rest/ESRI.ArcGIS.Rest.css">
 <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dijit/themes/tundra/tundra.css">
 <style type="text/css">html, body { height: 100%; width: 100%; margin: 0; padding: 0; }</style>
</head>
<body class="tundra">
<script type="text/javascript">var djConfig = {parseOnLoad: true};</script>
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.6"></script>
<script type="text/javascript" src="/ArcGIS/rest/services?f=json&callback=var ws_results ="></script>
<script type="text/javascript">
 dojo.require("dijit.layout.BorderContainer");
 dojo.require("dijit.layout.ContentPane");
 dojo.require("esri.map");
 var map;
 var hostName = document.location.host;
 function Init() {
  map = new esri.Map("mapDiv");
  //cycles through REST services and adds MapServer services to map
  for(var i=0; i<ws_results.services.length; i++){
   if (ws_results.services.type == 'MapServer') {
    layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://" + hostName + "/ArcGIS/rest/services/" + ws_results.services.name + "/MapServer");
    map.addLayer(layer);
   }
  }
  //resize the map when the browser resizes
  var resizeTimer;
  dojo.connect(map, 'onLoad', function(theMap) {
   dojo.connect(dijit.byId('mapDiv'), 'resize', function() {  //resize the map if the div is resized
    clearTimeout(resizeTimer);
    resizeTimer = setTimeout( function() {
     map.resize();
     map.reposition();
    }, 500);
   });
  });
 }
 dojo.addOnLoad(Init);
</script>
 <div id="mapContainer" dojotype="dijit.layout.BorderContainer" design="headline" gutters="false" style="width: 100%; height: 100%; margin: 0;">
  <div id="mapDiv" dojotype="dijit.layout.ContentPane" region="center" style="overflow:hidden;">
  </div>
 </div>
</body>
</html>
0 Kudos