Multiple call to a same webservice

24 views
Skip to first unread message

David Come

unread,
Jan 8, 2014, 10:06:02 AM1/8/14
to wsf-...@googlegroups.com
Hello.

I've created a simple web service whose implementation is
int SleeperImpl::sleep()
{
    int i=0;
     std::cout<<this<<" "<<i<<std::endl;
    ::sleep(10); //simulate some time consuming computation
    return 0;
}


The main idea beyond that piece of code is to test how staff handles several simultaneous calls to a same web service.
I test it with SoapUI where I launch 2 requests, the second one being delayed of 2 seconds.

I have to admit I'm a bit startled by the result.

Indeed, In the console, the same address for this is printed twice, proving it is the same web service which is called by staff.
But answers for SoapUI are delayed of the exact same time ! This proves that both requests are handled as soon as they arrived and run simultaneously for 8s.

How is that possible ?
The solution solution I see is something like this :
Sleeper* ptr_sleep= new SleeperImpl();
while(incomming_request){
  
  Thread(ptr_sleep,incomming_request->functionToCall());
}

Am i right ?
Thank you !

For those who wonder, I'm asking this because the SQL library I use is not thread safe. So for now, I have deported all SQl operations in an other class and I create a local object in the web service implementation

Alex Mantaut

unread,
Jan 8, 2014, 10:20:34 AM1/8/14
to wsf-...@googlegroups.com
Hi David:

I'm not sure I fully understand your question, The problem is that some critical section of your code (like that non thread safe SQL library call) is executed from 2 different threads at the same time?

If that's the case you should just mutex the critical section so it is not accessed from 2 places at once... The class Mutex does that...

Regards



2014/1/8 David Come <davi...@gmail.com>

--
 
---
You received this message because you are subscribed to the Google Groups "wsf-staff" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wsf-staff+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

David Come

unread,
Jan 8, 2014, 10:43:38 AM1/8/14
to wsf-...@googlegroups.com
The question is how internally staff works.

Im asking that question because I have a non thread safe SQL  library (Soci) that states : classes are not thread-safe, meaning that their instances should not be used concurrently by multiple threads.The simplest solution for multithreaded code is to set up a separate session object for each thread that needs to inteact with the database.
 
Up to now, I have been doing so with something like that

int Webservice::function(...)
{
  SQLHandler sql;
   int data=sql<<"QUERRY";

    return data;
}

In that way, I'm sure each time a call the webservice, the SQL connection is not shared.
But i was wondering if I could do otherwise.

Dmitry Utkin

unread,
Jan 8, 2014, 11:29:46 AM1/8/14
to wsf-...@googlegroups.com
Hi David,

By default Axis2/C handle each request in separate thread.

The solution for you could be using of Mutexes:


 MyServiceImpl.h

#include <staff/utils/Mutex.h>

class MyService: public staff::IService
{
public:
  virtual void op1();
  virtual void op2();

private:
  staff::Mutex mMutex;
};


 MyServiceImpl.cpp


void MyService::op1()
{
  staff::ScopedLock lock(mMutex);

  // thread non safe code
}

void MyService::op2()
{
  staff::ScopedLock lock(mMutex);

  // thread non safe code
}


среда, 8 января 2014 г., 19:43:38 UTC+4 пользователь David Come написал:
Reply all
Reply to author
Forward
0 new messages