Vertx WebClient when I don't use the connection for a period of time, I need to re-establish the connection instead of using my configuration - vert.x

val options =
WebClientOptions().setMaxPoolSize(1000)
.setKeepAlive(true)
.setKeepAliveTimeout(60 * 10)
.setTrustAll(true)
.setPoolCleanerPeriod(1000 * 60 * 10)
.setIdleTimeoutUnit(TimeUnit.MINUTES)
.setIdleTimeout(10)
.setMaxWaitQueueSize(1000)
.setConnectTimeout(1000 * 60 * 10)
webClient = WebClient.create(vertx, options)
vertx.http.clients.open-netsockets
It will return to 0 soon

as you set ConnectTimeout with huge number, you also need to increase also both these properties KeepAliveTimeout and setIdleTimeout.

Related

Firestore security rules for birthdate

I would like to have a Firestore security rule for bithdate field in my users collections where user age should be >=18 and <=80. I tried the following rule but I know it is not going to work especially for ages that are close to 18 or 80. Any idea how to make this work.
let now = request.time;
let thisYear = now.year();
let thisMonth = now.month();
let thisDay = now.day();
request.resource.data.birthdate >= timestamp.date(thisYear-80,thisMonth,thisDay) &&
request.resource.data.birthdate <= timestamp.date(thisYear-18,thisMonth,thisDay)
You can achieve the same result by comparing it with the request time but in seconds. here’s one example on how this will work:
function isAbove18(date) {
return date.seconds <= request.time.seconds - 18 * 365.25 * 24 * 60 * 60; //considering leap year with 0.25 🙃
}
function isBelow80(date) {
return date.seconds >= request.time.seconds - 80 * 365.25 * 24 * 60 * 60;
}
allow read, write: if isAbove18(resource.data.birthdate) && isBelow80(resource.data.birthdate);
For more about this you can go through this docs which takes some different approaches.

How do i format time into seconds in lua?

So basically I'm confused on how I'd make it so that I can convert DD:HH:MM:SS to only seconds while taking into account the amount of numbers there are. (Sorry if I make 0 sense, you should definitely know what I mean by the example below.)
print("05:00":FormatToSeconds()) -- 5 minutes and 0 seconds
-- 300
print("10:30:15":FormatToSeconds()) -- 10 hours, 30 minutes and 15 seconds
-- 37815
print("1:00:00:00":FormatToSeconds()) -- 1 day
-- 86400
print("10:00:00:30":FormatToSeconds()) -- 10 days, 30 seconds
-- 864030
So on and so forth. I think that maybe using gmatch would work but still idk. Help would be greatly appreciated.
Edit:
So I've tried doing it with gmatch, but I don't know if this is the most fastest way of doing this (which it probably isn't), so any help would still be appreciated.
(My code)
function ConvertTimeToSeconds(Time)
local Thingy = {}
local TimeInSeconds = 0
for v in string.gmatch(Time, "%d+") do
if tonumber(string.sub(v, 1, 1)) == 0 then
table.insert(Thingy, tonumber(string.sub(v, 2, 2)))
else
table.insert(Thingy, tonumber(v))
end
end
if #Thingy == 1 then
TimeInSeconds = TimeInSeconds + Thingy[1]
elseif #Thingy == 2 then
TimeInSeconds = TimeInSeconds + (Thingy[1] * 60) + Thingy[2]
elseif #Thingy == 3 then
TimeInSeconds = TimeInSeconds + (Thingy[1] * 60 * 60) + (Thingy[2] * 60) + Thingy[3]
elseif #Thingy == 4 then
TimeInSeconds = TimeInSeconds + (Thingy[1] * 24 * 60 * 60) + (Thingy[2] * 60 * 60) + (Thingy[3] * 60) + Thingy[4]
end
return TimeInSeconds
end
print(ConvertTimeToSeconds("1:00:00:00"))
Don't worry about execution speed before doing any actual measurements unless you're designing a time-critical program. In any extreme situation you'd probably want to offload risky parts to a C module.
Your approach is just fine. There are parts you can clean up: you can just return the results of calculations as TimeInSeconds doesn't actually act as accumulator in your case; tonumber handles '00' just fine and it can ensure decimal integers with an argument (since 5.3).
I'd go the other way and describe factors in a table:
local Factors = {1, 60, 60 * 60, 60 * 60 * 24}
local
function ConvertTimeToSeconds(Time)
local Components = {}
for v in string.gmatch(Time, "%d+") do
table.insert(Components, 1, tonumber(v, 10))
end
if #Components > #Factors then
error("unexpected time component")
end
local TimeInSeconds = 0
for i, v in ipairs(Components) do
TimeInSeconds = TimeInSeconds + v * Factors[i]
end
return TimeInSeconds
end
Of course, both implementations have problem with pattern being naïve as it would match e.g., '00 what 10 ever 10'. To fix that, you could go another route of using string.match with e.g., '(%d+):(%d+):(%d+):(%d+)' and enforcing strict format, or matching each possible variant.
Otherwise you can go all in and use LPeg to parse the duration.
Another way would be to not use strings internally, but instead convert them into a table like {secs=10, mins=1, hours=10, days=1} and then use these tables instead - getting seconds from that representation would be straight-forward.

how to reduce wait time in perl

I have script that queries a database a variable number of times per second.
For example, to achieve 36,000 queries per hour we input 600 queries per minute into our script. 600 x 60 = 36,000
This is the output we get you can see the delay between each query
{1} [2019-11-06 21:38:01.313]
{1} [2019-11-06 21:38:01.413]
{1} [2019-11-06 21:38:01.513]
{1} [2019-11-06 21:38:01.613]
{1} [2019-11-06 21:38:01.713]
{1} [2019-11-06 21:38:01.813]
My problem is we are missing out on that 0.0100 because we have a wait time inplace.
rates per minute = varies we can change this to a max of 960 queries per min but we would want fourmla that is flexible for 0-960.
my $wait_time = (1 / $rpm) * 60 * 1(connection); (max of 4 connections) wait time increases based on number of connections
Does anyone know how to reduce the wait time in between queries ?
thanks
This is the code line
my $wait_time = (1 / $rpm) * 60 * 1;
So when i enter in 600 queries per min
This code line calcuates the wait time based on number of connection we have
my $wait_time = (1 / 600) * 60 * 1;
1/600 * 60 * 1 = WAIT: 0.1
Well, your processing of the query needs time. A fragile solution, if i interpret your problem right, is to measure the time the current processing takes and substract that from the next sleep time. Of course that would break if the processing time equals or exceeds the sleep time.
A clean solution would be to have a dedicated main loop that does nothing but sleeping and firing off queries in separate threads.
I'm not sure if this will help because I have a very hard time understanding your question. I think you are concerned that you aren't making queries at the rate you desire.
It could be because you think of the wait time as being static. It's not the wait time that's static —that's dependent on how long the previous query took— it's the interval that's static.
use Time::HiRes qw( time sleep ); # Add support for fractional times.
my $interval = (1 / $qpm) * 60 * 1; # In (fractional) seconds.
my $next_run = time;
while (1) {
my $wait = $next_run - time;
sleep($wait) if $wait > 0;
$next_run += $interval;
... do work ...
}

How to get date range between two date in Google AppMaker?

I have two datebox that capture a start date & end date. I tried do following binding to get the date range between the two date but it return a negative value
#widget.root.children.DateBox1.value - #widget.root.children.DateBox2.value
following is my form example
// Binding (option 1 - no datasource)
getValidity(#widget.root.children.StartDate.value, #widget.root.children.EndDate.value);
// Binding (option 2 - with datasource)
getValidity(#datasource.item.StartDate, #datasource.item.EndDate);
// Client script
function getValidity(start, end) {
if (start && end) {
var milliseconds = end - start;
// days: 1000ms * 60s * 60m * 24h
return milliseconds / (1000 * 60 * 60 * 24);
// years: 1000ms * 60s * 60m * 24h * 365d
// return milliseconds / (1000 * 60 * 60 * 24 * 365);
}
return 'n/a';
}

Why Cookies will not be stored if setting Timeout = 30 days in GWT?

This is very weird. Ok, the below code works fine
public void setCookie(String cookiesName, String cookiesValue){
final int COOKIE_TIMEOUT = 1000 * 60 * 60 * 24;//1 days
Date expires = new Date((new Date()).getTime() + COOKIE_TIMEOUT);
Cookies.setCookie(cookiesName, cookiesValue, expires);
}
//then
setCookie("currentLang","de");
Collection<String> cookies = Cookies.getCookieNames();
for(String cookie : cookies){
if("currentLang".equals(cookie)){
System.out.println("got currentlang");
}
}
If i run the above code then I can see output: "got currentlang"
However, if I set timeout=30 days final int COOKIE_TIMEOUT = 1000 * 60 * 60 * 24 * 30;//30 days, then nothing got printed out, so "currentLang" has not even been stored if we set 30 days?
Why is that? does Gwt prevent that to happen?
You're using integer arithmetic for a sum that overflows beyond the maximum positive value for an integer. So 1000*60*60*24*30 is negative.
You could try 1000L*60*60*24*30