Skip to content

Commit

Permalink
Changing UUID generator to optimize task naming that was way too cost…
Browse files Browse the repository at this point in the history
…ly cause to UUID.randomUUID
  • Loading branch information
ngaud committed Mar 5, 2020
1 parent 78fed76 commit 3a85195
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion main/targetplatform/io.sarl.lang.targetplatform.target
Expand Up @@ -35,6 +35,7 @@
<unit id="org.jboss.tools.m2e.jdt.feature.feature.group" version="1.0.1.201209200903"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="http://dependencies.sarl.io"/>
<unit id="aopalliance" version="1.0.0"/>
<unit id="com.google.guava" version="27.1.0.jre"/>
<unit id="com.google.guava.testlib" version="27.1.0.jre"/>
Expand All @@ -44,7 +45,7 @@
<unit id="com.hazelcast" version="3.11.2"/>
<unit id="org.zeromq.jeromq" version="0.5.0"/>
<unit id="javax.inject" version="1.0.0"/>
<repository location="http://dependencies.sarl.io"/>
<unit id="java-uuid-generator" version="4.0.1"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://download.eclipse.org/releases/2019-12"/>
Expand Down
Expand Up @@ -32,7 +32,8 @@ Require-Bundle: io.sarl.core;bundle-version="0.11.0",
org.apache.log4j;bundle-version="1.2.15",
org.eclipse.xtend.lib;bundle-version="2.20.0",
stax2-api;bundle-version="4.2.0",
com.google.guava.failureaccess;bundle-version="1.0.1"
com.google.guava.failureaccess;bundle-version="1.0.1",
java-uuid-generator;bundle-version="4.0.1"
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %Bundle-Vendor
Export-Package: io.sarl.sre;
Expand Down
Expand Up @@ -20,6 +20,9 @@
*/
package io.sarl.sre.skills.bic

import com.fasterxml.uuid.EthernetAddress
import com.fasterxml.uuid.Generators
import com.fasterxml.uuid.impl.TimeBasedGenerator
import io.sarl.core.AgentTask
import io.sarl.core.Logging
import io.sarl.core.Time
Expand All @@ -38,6 +41,7 @@ import java.text.MessageFormat
import java.util.Map
import java.util.UUID
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentSkipListSet
import java.util.concurrent.ExecutionException
import java.util.concurrent.Future
import java.util.concurrent.TimeUnit
Expand All @@ -48,7 +52,6 @@ import javax.inject.Inject

import static io.sarl.sre.services.lifecycle.AgentLife.*
import static io.sarl.sre.services.lifecycle.BehaviorLife.*
import java.util.concurrent.ConcurrentSkipListSet

/**
* Skill that permits to execute tasks with an executor service.
Expand All @@ -69,7 +72,15 @@ skill SchedulesSkill extends Skill implements InternalSchedules {

var activeTaskRepository : ConcurrentHashMap<String, TaskDescription> = null

/** Constructor.
/**
* JUG Time based generator used for naming tasks, enough for this kind of missions not for a string unique UUID
* Goal: replace UUID.randomUUID that is way too slow in multithread context
*/
var uuidTimeBasedGenerator : TimeBasedGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());


/**
* Constructor.
*/
@Inject
new (service : ExecutorService) {
Expand Down Expand Up @@ -139,7 +150,9 @@ skill SchedulesSkill extends Skill implements InternalSchedules {
var description : TaskDescription = null
var realName : String
if (name.isNullOrEmpty) {
realName = "task-" + UUID::randomUUID.toString
// see http://www.cowtowncoder.com/blog/archives/2010/10/entry_429.html
//Don't use UUID::randomUUID way too slow
realName = "task-" + uuidTimeBasedGenerator.generate().toString
} else {
realName = name

Expand Down

0 comments on commit 3a85195

Please sign in to comment.