Skip to content

Instantly share code, notes, and snippets.

@AlexArcPy
Last active May 23, 2023 04:45
Show Gist options
  • Save AlexArcPy/18eb9cea4242b5cef55a2004d2dadf66 to your computer and use it in GitHub Desktop.
Save AlexArcPy/18eb9cea4242b5cef55a2004d2dadf66 to your computer and use it in GitHub Desktop.
Sample: Stress testing ArcGIS Server map service with the Python multiprocessing module and ArcREST exporting many map images in parallel
import multiprocessing
from arcrest import AGSTokenSecurityHandler
from arcrest.ags.server import Server
from arcrest.common.geometry import Envelope
ags_admin_url = r"http://localhost:6080/arcgis/admin"
ags_security_handler = AGSTokenSecurityHandler(username="username",
password="password",
org_url=ags_admin_url)
ags_rest_services_directory_user_url = r"http://localhost:6080/arcgis"
ags_service_obj = Server(ags_rest_services_directory_user_url,
ags_security_handler)
service_name = "SampleWorldCities"
ags_services = ags_service_obj.services
ags_mapservice = [ags_service for ags_service in ags_services
if service_name in ags_service.url][0]
bbox_envelope = Envelope(1590464.1952204683, 7544716.127883499,
1598001.8017391723, 7546481.8772778595,
wkid=3857)
def handler_export_map_images():
p = multiprocessing.Pool(10)
result = p.apply_async(worker_export_map_images,[5])
result.get()
p.map(worker_export_map_images, range(1000))
def worker_export_map_images(x):
result = ags_mapservice.exportMap(bbox_envelope,
size="600,550",
dpi=200)
return
if __name__ == '__main__':
handler_export_map_images()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment