Do I need call monkey.patch_all() in Django+Gunicorn+GEvent+Boto structure? - boto

My website is using Django+Gunicorn+GEvent.
There is a function which I have to use Boto for DynamoDB.
Do I need call monkey.patch_all() to make Boto become greenlet?

If you use the default worker_class configuration, then you don't have the features of gevent. Look the doc here. I think you don't have the advantage of using gevent when you use the default configuration even though you monkey patch all.
So you should configure gunicorn to use the GeventWorker which does the monkey.patch_all() operation and in this situation, I think you don't have to monkey patch all. Here is the source code of GeventWorker and the doc about worker_class

Related

Library class doesn't know of ConfigureWebHostDefaults extension method

I'm building a suite of REST micro-services using .Net Core 3.0 Preview 6. All these services will have the same start up logic. So, I'm trying to place all the code in a .Net Standard library.
The goal is to have the IHostBuilder:CreateHostBuilder method, as well as the Startup:Configure and Startup:ConfigureServices class and methods in the library. The library will also contain error handling logic, customized http response messages, etc.
However, I can't seem to find the correct package that contains the ConfigureWebHostDefaults method. I tried adding the Microsoft.AspNetCore package 2.2.0, but that didn't resolve the issue.
I added the Microsoft.Extensions.Hosting (3.0.0-preview-6) package, that also doesn't resolve the issue.
Is what I'm attempting even possible?
Thanks
-marc
I resolved it, not the best way, but it works. I decided to make the library targeted specifically for .NET Core 3.0. So, I changed the targetframework in the project file. That change automatically resolved my other issue.
Import the Microsoft.AspNetCore package, and use WebHost.CreateDefaultBuilder() instead. According to the code it is built from, both CreateDefaultBuilder() and ConfigureWebHostDefaults() call the same internal method: ConfigureWebDefaults().
The only downside of this is that the returned host will be an IWebHost instead of an IHost.

Lambda function calling another Lambda function

I want to create a Lambda function that runs through S3 files and if needed triggers other Lambda functions to parse the files in parallel.
Is this possible?
Yes it's possible. You would use the AWS SDK (which is included in the Lambda runtime environment for you) to invoke other Lambda functions, just like you would do in code running anywhere else.
You'll have to specify which language you are writing the Lambda function in if you want a more detailed answer.
If I understand your problem correctly you want one lambda that goes through a list of files in a S3-bucket. Some condition will decide whether a file should be parsed or not. For the files that should be parsed you want another 'file-parsing' lambda to parse those files.
To do this you will need two lambdas - one 'S3 reader' and one 'S3 file parser'.
For triggering the 'S3 file parser' lambda you have many few different options. Here are a two:
Trigger it using a SNS topic. (Here is an article on how to do that). If you have a very long list of files this might be an issue, as you most likely will surpass the number of instances of a lambda that can run in parallel.
Trigger it by invoking it with the AWS SDK. (See the article 'Leon' posted as comment to see how to do that.) What you need to consider here is that a long list of files might cause the 'S3 reader' lambda that controls the invocation to timeout since there is a 5 min runtime limit for a lambda.
Depending on the actual use case another potential solution is to just have one lambda that gets triggered when a file gets uploaded to the S3 bucket and let it decide whether it should get parsed or not and then parse it if needed. More info about how to do that can be found in this article and this tutorial.

how to reinitialize log4j2 configuration?

After an initial configuration of log4j2 with:
Configurator.initialize(null, configLocation);
I would like to reinitialize it with a different URL
Configurator.initialize(null, configLocation2);
The problem is that the second call is ignored. I believe that once the LoggerContext is STARTED it will ignore reconfigurations.
Is there a way to do this?
Once you have a LoggerContext you can call
context.setConfigLocation(configLocation)
where configLocation is a URI. That will force a reconfiguration.

How to configure NearCache with Hazelcast 3.5 without an explicit Client

Based on this question, I'm trying to switch to the version 3.5-EA of Hibernate.
Up to now I had a configuration like this:
CacheConfiguration<K, V> configuration = new CacheConfig<K, V>()
.setNearCacheConfig(new NearCacheConfig().setInMemoryFormat(InMemoryFormat.OBJECT))
.setExpiryPolicyFactory(createExpiryPolicyFactory(expiryDuration));
cache = cacheManager.createCache(cacheName, configuration);
But now the setNearCacheConfig method is gone. There only exists a addNearCacheConfig on the ClientCacheConfig. But I don't have a ClientCacheConfig.
I basically don't know where to put the NearCacheConfig.
the configuration of the nearcache can be done on the client side. http://docs.hazelcast.org/docs/3.5/manual/html-single/hazelcast-documentation.html#hazelcast-java-client
If you do not want to use xml for configuration (http://docs.hazelcast.org/docs/latest/manual/html-single/hazelcast-documentation.html#near-cache) - you could probably do something like this -
Config cfg = new Config();
MapConfig mc = new MapConfig();
mc.setNearCacheConfig(new NearCacheConfig());
cfg.addMapConfig(mc);
HazelcastInstance hi = Hazelcast.newHazelcastInstance(cfg);
As per my opinion, NearCache feature is useful when you are using Client-Server hazelcast api and when youa re trying to access cache externally, but if you are gonna make call within hazelcast cluster internally and do not want to use Hazelcast client api than there no need to use NearCache feature.
Since there will not be any benefit out of it.

How can I add a contextListener in logback groovy configuration?

I want to use LevelChangePropagator as logback contextListener, as described in the logback manual. However in my project logback is configured using groovy, and there's nothing in the official documentation about configuring contextListener in groovy. Logback provides a tool to translate xml configuration into a groovy configuration. I tried it, but it just skipped the contextListener part.
I've found exactly one answer to my question in the logback mailing lists, but solution doesn't seem to be working for me.
EDIT:
I've created an issue in logback JIRA about missing documentation: http://jira.qos.ch/browse/LOGBACK-979. Still, maybe someone knows the answer?
Add this to logback.groovy:
import ch.qos.logback.classic.jul.LevelChangePropagator
def lcp = new LevelChangePropagator()
lcp.context = context
lcp.resetJUL = true
context.addListener(lcp)