java - Thread VS RabbitMQ Worker resource consumption -


i using java executorservice threads send amazon emails, helps me make concurrent connection amazonses via api , sends mails @ lightning speed. amazon accepts number of connection in sec, me 50 requests in second. execute 50 threads in second , send around 1million emails daily.

this working pretty good, number of mails going increased. , don't want invest more ram , processors.

one of friend suggested me use rabbitmq workers instead of threads, instead of 50 threads, ll having 50 workers job.

so before changing code test resource management, want know there huge difference in consumption? when execute threads, java consumes 20-30% of memory. if used workers low or high?

or alternative option this? here thread email sending function:

@override public void run() {     destination destination = new destination().withtoaddresses(new string[] { this.to });     content subject = new content().withdata(subject);     content textbody = new content().withdata(body);     body body = new body().withhtml(textbody);     message message = new message().withsubject(subject).withbody(body);     sendemailrequest request = new sendemailrequest().withsource(from).withdestination(destination).withmessage(message);     connection connection = new connection();     java.util.date dt = new java.util.date();     java.text.simpledateformat sdf = new java.text.simpledateformat("yyyy-mm-dd hh:mm:ss");     string insert = "";     try {         system.out.println("attempting send email " + this.to);          ctr++;         client.sendemail(request);         insert = "insert email_histories (campaign_id,contact_id,group_id,is_opened,mail_sent_at,mail_opened_at,ip_address,created_at,updated_at,is_sent) values (" + this.campaign_id + ", " + this.contact_id + ", " + this.group_id + ", false, '" + sdf.format(dt) + "', null, null, '" + sdf.format(dt) + "', '" + sdf.format(dt) + "', true);";         connection.insert(insert);         system.out.println("email sent! " + this.to);     } catch (exception ex) {         system.out.println("the email not sent.");         system.out.println("error message: " + ex.getmessage());     }  } 

i have no experience rabbitmq, i'll have leave others answer.

or alternative option this?

instead of using 1 thread per mail, move code inside runable. add shared semaphore number of permits = number of mails want send per second. take 1 permit per mail, refill permits every second thread (i.e. separate schedledexecutorservice or timer). adjust executor thread pool size whatever server can handle.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -