This example demonstrates a service, implemented in Scala, that calculates the Mandelbrot set over a specified area (of the complex plane) and returns an image of that area that represents the set.
The example consists of one web resource implemented by the following:
mandel.MandelService
The mapping of the URI path space is presented in the following table:
URI path |
Resource class |
HTTP methods |
---|---|---|
({lx},{ly}),({ux},{uy}) |
MandelResource |
GET |
The URI template, “({lx},{ly}),({ux},{uy})”, embeds the bottom left had corner and the top right hand corner of the area to calculate as template variables. The following query parameters are supported by MandelResource:
Query parameter |
Default Value |
Description |
---|---|---|
imageSize |
512 |
The maximum size of the image in width or height |
limit |
512 |
The limit on the number of iterations to determine if a point on the complex plane belongs to the Mandelbrot set. |
workers |
8 |
The number of Scala actors instantiated to |
The URI template, “({lx},{ly}),({ux},{uy})”, embeds the bottom left had corner and the top right hand corner of the area to calculate.
The implementation utilizes Scala actors to calculate the set concurrently. If a system can avail of many hardware threads of multiple cores in a single chip then the Mandelbrot set can be calculated in parallel. The number of concurrent actors can be modified by the query parameter “workers”. Such a parameter should not really be required as Scala's event-based actors are cheap to construct and in theory the runtime should utilize has many threads as the hardware and configuration allows to concurrently process actors. However, it is useful for testing and verifying performance increases (yet to be verified with this implementation!).
Run the example as follows:
mvn clean compile exec:java
then go to the URL http://localhost:9998/mandelbrot/(-2.2,-1.2),(0.8,1.2).
Test on multi-core machine to see if performance is improved.
Assign Etags based on the area to calculate the image size and the limit.
A client that enables one to zoom into the set
A client that enables one to browse the set a bit like the way Google maps works. This would be an example of scaling out.