Search in sources :

Example 26 with Request

use of io.fabric8.insight.metrics.model.Request in project fabric8 by jboss-fuse.

the class InvocationTest method testUnderLoadSyncObject.

@Test(timeout = 30 * 1000)
public void testUnderLoadSyncObject() throws Exception {
    HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
    DispatchQueue queue = Dispatch.createQueue();
    ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
    server.start();
    ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
    client.start();
    try {
        final HelloImpl helloImpl = new HelloImpl();
        server.registerService("service-id", new ServerInvoker.ServiceFactory() {

            public Object get() {
                return helloImpl;
            }

            public void unget() {
            }
        }, HelloImpl.class.getClassLoader());
        InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
        final Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
        assertEquals("Hello World!", hello.helloworld());
        final AtomicInteger requests = new AtomicInteger(0);
        final AtomicInteger failures = new AtomicInteger(0);
        final long[] latencies = new long[BENCHMARK_CLIENTS * BENCHMARK_INVOCATIONS_PER_CLIENT];
        final long start = System.nanoTime();
        Thread[] threads = new Thread[BENCHMARK_CLIENTS];
        for (int t = 0; t < BENCHMARK_CLIENTS; t++) {
            final int thread_idx = t;
            threads[t] = new Thread() {

                public void run() {
                    for (int i = 0; i < BENCHMARK_INVOCATIONS_PER_CLIENT; i++) {
                        try {
                            requests.incrementAndGet();
                            String response;
                            final long start = System.nanoTime();
                            response = hello.hello("Fabric");
                            final long end = System.nanoTime();
                            latencies[(thread_idx * BENCHMARK_INVOCATIONS_PER_CLIENT) + i] = end - start;
                            assertEquals("Hello Fabric!", response);
                        } catch (Throwable t) {
                            latencies[(thread_idx * BENCHMARK_INVOCATIONS_PER_CLIENT) + i] = -1;
                            failures.incrementAndGet();
                            if (t instanceof UndeclaredThrowableException) {
                                t = ((UndeclaredThrowableException) t).getUndeclaredThrowable();
                            }
                            System.err.println("Error: " + t.getClass().getName() + (t.getMessage() != null ? " (" + t.getMessage() + ")" : ""));
                        }
                    }
                }
            };
            threads[t].start();
        }
        for (int t = 0; t < BENCHMARK_CLIENTS; t++) {
            threads[t].join();
        }
        final long end = System.nanoTime();
        long latency_sum = 0;
        for (int t = 0; t < latencies.length; t++) {
            if (latencies[t] != -1) {
                latency_sum += latencies[t];
            }
        }
        double latency_avg = ((latency_sum * 1.0d) / requests.get()) / MILLIS_IN_A_NANO;
        double request_rate = ((requests.get() * 1.0d) / (end - start)) * SECONDS_IN_A_NANO;
        System.err.println(String.format("Requests/Second: %,.2f", request_rate));
        System.err.println(String.format("Average request latency: %,.2f ms", latency_avg));
        System.err.println("Error Ratio: " + failures.get() + " / " + requests.get());
    } finally {
        server.stop();
        client.stop();
    }
}
Also used : ServerInvoker(io.fabric8.dosgi.io.ServerInvoker) HashMap(java.util.HashMap) InvocationHandler(java.lang.reflect.InvocationHandler) ClientInvokerImpl(io.fabric8.dosgi.tcp.ClientInvokerImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ServerInvokerImpl(io.fabric8.dosgi.tcp.ServerInvokerImpl) DispatchQueue(org.fusesource.hawtdispatch.DispatchQueue) Test(org.junit.Test)

Example 27 with Request

use of io.fabric8.insight.metrics.model.Request in project fabric8 by jboss-fuse.

the class ChildAutoScaler method getChildScalingRequirements.

protected ChildScalingRequirements getChildScalingRequirements(AutoScaleRequest request) {
    ChildScalingRequirements scalingRequirements = null;
    ProfileRequirements profileRequirements = request.getProfileRequirements();
    if (profileRequirements != null) {
        scalingRequirements = profileRequirements.getChildScalingRequirements();
    }
    return scalingRequirements;
}
Also used : ProfileRequirements(io.fabric8.api.ProfileRequirements) ChildScalingRequirements(io.fabric8.api.ChildScalingRequirements)

Example 28 with Request

use of io.fabric8.insight.metrics.model.Request in project fabric8 by jboss-fuse.

the class ChildAutoScaler method createContainers.

@Override
public void createContainers(AutoScaleRequest request) throws Exception {
    int count = request.getDelta();
    String profile = request.getProfile();
    String version = request.getVersion();
    FabricService fabricService = request.getFabricService();
    CreateChildContainerOptions.Builder builder = null;
    if (fabricService != null) {
        builder = createAutoScaleOptions(request, fabricService);
    }
    if (builder != null) {
        Set<String> ignoreContainerNames = new HashSet<>();
        for (int i = 0; i < count; i++) {
            final CreateChildContainerOptions.Builder configuredBuilder = builder.number(1).version(version).profiles(profile);
            Container[] containers = fabricService.getContainers();
            NameValidator nameValidator = Containers.createNameValidator(containers);
            String name = Containers.createAutoScaleContainerName(containers, profile, containerProvider.getScheme(), nameValidator);
            ignoreContainerNames.add(name);
            CreateChildContainerOptions options = configuredBuilder.name(name).build();
            LOG.info("Creating container name " + name + " version " + version + " profile " + profile + " " + count + " container(s)");
            fabricService.createContainers(options);
        }
    } else {
        LOG.warn("Could not create version " + version + " profile " + profile + " due to missing autoscale configuration");
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) CreateChildContainerOptions(io.fabric8.api.CreateChildContainerOptions) NameValidator(io.fabric8.api.NameValidator) HashSet(java.util.HashSet)

Example 29 with Request

use of io.fabric8.insight.metrics.model.Request in project fabric8 by jboss-fuse.

the class MetricsTest method testDefault.

@Test
public void testDefault() throws Exception {
    Query query = new Query("test", new HashSet<Request>(Arrays.asList(new MBeanAttrs("memory", "java.lang:type=Memory", Arrays.asList("HeapMemoryUsage", "NonHeapMemoryUsage")), new MBeanOpers("deadlocks", "java.lang:type=Threading", "dumpAllThreads", Arrays.<Object>asList(true, true), Arrays.<String>asList(boolean.class.getName(), boolean.class.getName())))), null, null, null, 0, 0);
    System.gc();
    QueryResult qrs = JmxUtils.execute(new Server("local"), query, ManagementFactory.getPlatformMBeanServer());
    String output = new Renderer().render(qrs);
    Map map = new ObjectMapper().readValue(output, Map.class);
    assertEquals("local", map.get("host"));
    assertNotNull(map.get("@timestamp"));
}
Also used : QueryResult(io.fabric8.insight.metrics.model.QueryResult) Query(io.fabric8.insight.metrics.model.Query) Server(io.fabric8.insight.metrics.model.Server) Request(io.fabric8.insight.metrics.model.Request) Renderer(io.fabric8.insight.metrics.mvel.Renderer) MBeanOpers(io.fabric8.insight.metrics.model.MBeanOpers) MBeanAttrs(io.fabric8.insight.metrics.model.MBeanAttrs) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 30 with Request

use of io.fabric8.insight.metrics.model.Request in project fabric8 by jboss-fuse.

the class HttpMappingRuleResolver method findMappingRule.

public HttpMappingResult findMappingRule(HttpServletRequest request, HttpServletResponse response) {
    String requestURI = request.getRequestURI();
    String contextPath = request.getContextPath();
    MappingResult answer = null;
    if (contextPath != null && contextPath.length() > 0 && !contextPath.equals("/")) {
        String requestWithoutContextPath = requestURI.substring(contextPath.length());
        answer = resolver.findMappingRule(requestWithoutContextPath);
    }
    if (answer == null) {
        // lets try the full request URI with the context path to see if that maps
        answer = resolver.findMappingRule(requestURI);
    }
    return answer != null ? new HttpMappingResult(answer) : null;
}
Also used : MappingResult(io.fabric8.gateway.support.MappingResult)

Aggregations

IOException (java.io.IOException)17 HashMap (java.util.HashMap)9 File (java.io.File)8 Test (org.junit.Test)8 ByteArrayInputStream (java.io.ByteArrayInputStream)5 MalformedURLException (java.net.MalformedURLException)5 Map (java.util.Map)5 FabricService (io.fabric8.api.FabricService)4 RuntimeProperties (io.fabric8.api.RuntimeProperties)4 AbstractRuntimeProperties (io.fabric8.api.scr.AbstractRuntimeProperties)4 MavenResolver (io.fabric8.maven.MavenResolver)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Date (java.util.Date)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Container (io.fabric8.api.Container)3 NameValidator (io.fabric8.api.NameValidator)3 FileInputStream (java.io.FileInputStream)3