Modern software systems often employ dynamic adaptation to runtime conditions in some parts of their functionality – well known examples range from autotuning of computing kernels through adaptive battery saving strategies of mobile applications to dynamic load balancing and failover functionality in computing clouds. Typically, the implementation of these features is problem-specific – a particular autotuner, a particular load balancer, and so on – and enjoys little support from the implementation environment beyond standard programming constructs.

We propose Adaptive Dispatch as a generic coding pattern useful for implementing dynamic adaptation. We believe that such pattern can make the implementation of dynamic adaptation features better in multiple aspects – for example, an explicit adaptation construct makes the presence of adaptation easily visible to programmers and ready for manipulation with development tools, it also facilitates coordination of adaptation behavior at runtime. We present an implementation of the Adaptive Dispatch pattern as an internal DSL in Scala. [1]

  1. P. Kubát, L. Bulej, T. Bureš, V. Horký, P. Tůma: Adaptive Dispatch: A Pattern for Performance-Aware Software Self-Adaptation, in Companion Proc. 9th ACM/SPEC Intl. Conf. on Performance Engineering (ICPE), pp. 195-198, 2018, ISBN: 978-1-4503-5629-9, DOI: 10.1145/3185768.3186406

Code example

def parseWithGson(json: String, targetClass: Class[TData]): TData = {
  gson.fromJson(json, targetClass)
}

def parseWithJackson(json: String, targetClass: Class[TData]): TData = {
  objectMapper.readValue(json, targetClass)
}

/*
 * Use parseJson as normal function, faster implementation will be
 * selected automatically.
 */
val parseJson = parseWithGson _ or parseWithJackson

Contributors

Downloads

Contact