Return-Path: X-Original-To: apmail-zest-dev-archive@minotaur.apache.org Delivered-To: apmail-zest-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1B85517E40 for ; Thu, 2 Apr 2015 08:05:57 +0000 (UTC) Received: (qmail 76002 invoked by uid 500); 2 Apr 2015 08:05:57 -0000 Delivered-To: apmail-zest-dev-archive@zest.apache.org Received: (qmail 75969 invoked by uid 500); 2 Apr 2015 08:05:56 -0000 Mailing-List: contact dev-help@zest.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zest.apache.org Delivered-To: mailing list dev@zest.apache.org Received: (qmail 75957 invoked by uid 99); 2 Apr 2015 08:05:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Apr 2015 08:05:56 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of hedhman@gmail.com designates 209.85.213.178 as permitted sender) Received: from [209.85.213.178] (HELO mail-ig0-f178.google.com) (209.85.213.178) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Apr 2015 08:05:52 +0000 Received: by igbqf9 with SMTP id qf9so66903910igb.1 for ; Thu, 02 Apr 2015 01:04:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=JFcLAnKwnsajJmjub2mgoJZ/Loe+//hki6oR7bKw0Ak=; b=QmbLekIs2b0Q7klPDQ/4KmYB85No3uazrdy/29nDFhQLNdKjp0jNDriYlY34qEplvr KOnNRra6yhIe7nGCgmnux0Ghlpz4gr+FyKITUujwo29JF9Ac+aUdqSenk+2i7MLgJQ0j 2EslyoX2kdhr4jsSb6DeUxJERqafLux6Qfxe2Y3s2+4YRwFgwnbmqJYacytusZDltkGt Ejoky//6j7cR7xXLKqkH/G296YvnlUmBSonQn7lQ2zLcXltHOkwF/4HgMfeRIOC4u34c sCRXctykdQ4LYX/PHaVi27lvX/mdQYRgKupfLJFg3XxGiG06bRzvY7TQpe5g1qcJjI6p WcWw== X-Received: by 10.42.27.143 with SMTP id j15mr9410292icc.28.1427961841981; Thu, 02 Apr 2015 01:04:01 -0700 (PDT) MIME-Version: 1.0 Sender: hedhman@gmail.com Received: by 10.36.44.70 with HTTP; Thu, 2 Apr 2015 01:03:41 -0700 (PDT) In-Reply-To: <2e5cec64-6b24-49e9-bfe6-1111459d71ac@googlegroups.com> References: <551C4659.8050007@gmail.com> <2e5cec64-6b24-49e9-bfe6-1111459d71ac@googlegroups.com> From: Niclas Hedhman Date: Thu, 2 Apr 2015 11:03:41 +0300 X-Google-Sender-Auth: PEMQkivDpCvGpJB1QGnbXu039dI Message-ID: Subject: Re: [qi4j-dev] Using Qi4j as a skeleton framework in a high throughput, highly concurrent servlet deployment (and problems with race conditions) To: Tasos Parisinos Cc: dev Content-Type: multipart/alternative; boundary=20cf3040ec065820a20512b9464a X-Virus-Checked: Checked by ClamAV on apache.org --20cf3040ec065820a20512b9464a Content-Type: text/plain; charset=UTF-8 The general "rule" is that Factories (i.e. implemented by Module nowadays) should be thread safe, Builders are NOT thread-safe, and are expected to be created at each use. Are you trying to re-use the Builders? If not, i.e. you do newXyzBuilder() on each use, and you are seeing threading issues, then that is bug(s) and I would love to get hold of the details. ValueComposites -> thread-safe by definition, once created. EntityComposites -> MUST NOT be handed between threads, and is therefor indirectly thread-safe. TransitentComposites -> Internals are expected to be thread-safe, but changes at 'user level' needs to be taken care of. ServiceComposites -> Internals are expected to be thread-safe, but user level might need care. ConfigurationComposites -> They are entities, and therefor inherits concurrency characteristics. Qi4j isn't really intended for being a speed demon, so 15000 tx/sec sounds a bit too ambitious to me. Please report back what kind of numbers you will eventually manage, even if it is not good enough for you. Niclas P.S. Qi4j has just been accepted into the Apache Software Foundation, and will emerge as Apache Zest. dev@zest.apache.org is CC'd for that reason. On Wed, Apr 1, 2015 at 10:50 PM, Tasos Parisinos wrote: > Thanx for you reply Kent > > I agree with you that builder instances should be created used and > discarded inside a single request (a single thread from the servlet > container pool). The builder factories though, as the application itself > should be used commonly across all request threads (in a synchronized > manner) in order to avoid instantiating such an application PER thread, as > this will greatly compromise performance. The use of putIfAbsent in that > context seems to be corrent. I'll give it a try and update you with results > > > On Wednesday, April 1, 2015 at 10:26:16 PM UTC+3, kent.soelvsten wrote: >> >> I am not an expert so it might be the blind leading the deaf ...... >> >> but i sense a potential problem with concurrent access to various >> variants of ValueBuilderFactory#newValueBuilder and >> TransientBuilderFactory#newTransientBuilder. >> (the internal usage of ConcurrentHashMap inside TypeLookup - shouldn't we >> use putIfAbsent?). >> >> So that would be good candidates for synchronization. If that solves your >> problem i believe you might have found a bug - and a work-around. >> ValueBuilder and TransientBuilder instances should probably be created, >> used and discarded inside a single web request and not reused. >> >> /Kent >> >> >> Den 01-04-2015 kl. 20:07 skrev Tasos Parisinos: >> >> Hi all >> >> Let me describe my problem. We have implemented a servlet (deployed in >> tomcat) that takes a REST request and based on its query parameters, it >> builds and executes a single query (using Hibernate ORM) within a JTA >> transaction (using Atomikos). The application specifics are not important, >> what is important is that we need high throughput (15.000 trx / sec is our >> objective). >> >> We have implemented all infrastructure code using Qi4j for COP and DI >> as well as Property data validation (constraint annotations). In >> deployment time (in a separate thread) we assemble and activate two Qi4j >> runtimes, each with a Qi4j application. The first is used only during >> deployment, while the second is used in ALL threads that serve requests. >> Using Qi4j this second application, starts various ServiceComposite while >> the servlet deployes, for eager initialization (logger service, mapping >> service, repository service, rest service, application services, domain >> services, transaction service, token service to name only some). We >> implement our Use Cases with a DCI design. >> >> These services and DCI code uses various ValueBuilder and >> TransientBuilder to do composition. >> >> The problem is: >> >> Because ALL request threads, use the same Qi4j application, we have >> various race conditions that are mainly associated with the various >> builders. These race conditions appear when the servlet serves more that >> 2000 trx / sec. Sacrificing some throughput we can synchronize shared >> variables, but to minimize performance impact we need to know: >> >> 1. What is the best practice for such cases >> 2. Which part of ValueBuilderFactory, ValueBuilder, >> TransientBuilderFactory, TransientBuilder is best to synchronize? >> >> Thanx in advance >> >> -- >> You received this message because you are subscribed to the Google Groups >> "qi4j-dev" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to qi4j-dev+u...@googlegroups.com. >> To post to this group, send email to qi4j...@googlegroups.com. >> Visit this group at http://groups.google.com/group/qi4j-dev. >> For more options, visit https://groups.google.com/d/optout. >> >> >> -- > You received this message because you are subscribed to the Google Groups > "qi4j-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to qi4j-dev+unsubscribe@googlegroups.com. > To post to this group, send email to qi4j-dev@googlegroups.com. > Visit this group at http://groups.google.com/group/qi4j-dev. > For more options, visit https://groups.google.com/d/optout. > -- Niclas Hedhman, Software Developer http://www.qi4j.org - New Energy for Java --20cf3040ec065820a20512b9464a--